android - 将项目移植到 Android Studio 时如何使用旧的 .jar 文件?

标签 android android-studio gradle

我能够创建一个新的 AndroidStudio 项目并将我的旧代码移植到其中。

但是现在我收到一些关于某些库(例如 Flurry)无法识别的编译错误。

请参阅此屏幕截图,其中对 Flurry 的引用为红色:

enter image description here

这就是我的旧 .jar 的样子:

enter image description here

我需要通过什么方式来移植 jar ?现在应该通过 Gradle 来处理吗?我该怎么做呢?现在我的 Gradle 文件如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "problemio.com.problemionew"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
}

我应该添加如下行:

compile 'com.android.support:acra-4.2.3'
compile 'com.android.support:android-support-v4'
compile 'com.android.support:FlurryAgent'
compile 'com.android.support:gcm-server'
compile 'com.android.support:gcm'

最佳答案

如果您想将 jar 添加到项目中,请将 jar 移至 libs 文件夹并在成绩文件中执行以下操作:

compile files 'your.jar.file.name.here.jar'

对于您要导入的每个 jar。

这应该可以解决问题。

文件夹看起来像:

folder heirarchy

然后依赖项 block 将类似于:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'

    compile files('libs/android_antlib_4-12-0.jar')
}

关于android - 将项目移植到 Android Studio 时如何使用旧的 .jar 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34302690/

相关文章:

带有 C++ UnsatisfiedLinkError 的 Android Studio JNI

Android Studio 3.0 - 设置未保存

android - Android Instrumented Test有时会起作用,有时会无法生成覆盖率

android - Gradle任务执行android zipalign

android - fragment 的生命周期回调没有被相应地调用

java - Android 应用程序的理想 CPU 百分比

android - Android Auto 中未列出的应用程序

android - 相当于 'configurations.properties'文件的Gradle

android - 加快 Android Studio 中的运行过程

android - 本地 gradle 仓库镜像