【问题标题】:Migration from Eclipse to Android Studio: Proguard errors with libraryjars从 Eclipse 迁移到 Android Studio:使用 libraryjars 的 Proguard 错误
【发布时间】:2016-02-11 07:43:41
【问题描述】:

我已将 Eclipse 项目迁移到 Android Studio。我在我的项目中使用了三个模块和以下 jar 文件作为库。

build.gradle 具有依赖关系:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        applicationId "com.xxx.xxxxxxxx"
        minSdkVersion 10
        targetSdkVersion 22
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
    productFlavors {
    }
}

dependencies {
    compile project(':aFileChooser')
    compile files('libs/aquery.jar')
    compile files('libs/google-api-client-1.10.3-beta.jar')
    compile files('libs/google-api-client-android2-1.10.3-beta.jar')
    compile files('libs/google-http-client-1.10.3-beta.jar')
    compile files('libs/google-http-client-android2-1.10.3-beta.jar')
    compile files('libs/google-oauth-client-1.10.1-beta.jar')
    compile files('libs/httpclient-4.3.3.jar')
    compile files('libs/httpcore-4.3.2.jar')
    compile files('libs/httpmime-4.3.3.jar')
    compile files('libs/jackson-core-asl-1.9.4.jar')
    compile files('libs/jsr305-1.3.9.jar')
    compile files('libs/maps.jar')
    compile 'com.google.guava:guava:11.0.1'
    compile 'com.google.protobuf:protobuf-java:2.2.0'
    compile 'com.google.android.gms:play-services:7.0.0'
    compile('com.google.android.gms:play-services-gcm:7.0.0') {
        exclude group: 'com.google.guava'
        exclude group: 'com.apache.http'
    }
    compile('com.google.android.gms:play-services-maps:7.0.0') {
        exclude group: 'com.google.guava'
        exclude group: 'com.apache.http'
    }
}

我的 libs 文件夹包含以下 jars

proguard-project.txt

-keep class com.google.** {*;}
-keep interface com.google.** { *;}
-keep class com.slidingmenu.** {*;}
-keep class com.actionbarsherlock.** {*;}
-keep class com.ipaulpro.** {*;}
-keep class com.ianhanniballake.** {*;}

-dontwarn com.google.**
-dontwarn com.androidquery.**
-dontwarn org.apache.http.**
-dontwarn com.ianhanniballake.**
-dontwarn com.ipaulpro.**

-libraryjars /libs/google-api-client-1.10.3-beta.jar
-libraryjars /libs/google-api-client-android2-1.10.3-beta.jar
-libraryjars /libs/google-http-client-1.10.3-beta.jar
-libraryjars /libs/google-http-client-android2-1.10.3-beta.jar
-libraryjars /libs/google-oauth-client-1.10.1-beta.jar
-libraryjars /libs/jackson-core-asl-1.9.4.jar
-libraryjars /libs/guava-11.0.1.jar
-libraryjars /libs/jsr305-1.3.9.jar
-libraryjars /libs/protobuf-java-2.2.0.jar
-libraryjars /libs/maps.jar
-libraryjars /libs/httpclient-4.3.3.jar
-libraryjars /libs/httpcore-4.3.2.jar
-libraryjars /libs/httpmime-4.3.3.jar

所有事情最终都完成了,我也可以运行我的项目,但是当我尝试 Generate Sign Apk 它给我的错误如下:

Errors in Pastebin

我不知道为什么会这样,因为它在 Eclipse 中完美运行。

有什么帮助吗?

【问题讨论】:

  • 发布你的整个 build.gradle。
  • 更新了整个代码。
  • 仔细检查文件是否存在?? IOException:无法读取 [/libs/google-api-client-1.10.3-beta.jar]

标签: java android eclipse proguard android-proguard


【解决方案1】:

首先,Android 已经提供了 Apache HTTPClient 的实现。不要添加对另一个的依赖。

日志文件的底部显示失败消息:

无法读取 [/libs/google-api-client-1.10.3-beta.jar](没有这样的文件或目录)

您可以简单地将所有库中的 jar 添加为编译依赖项,只需一行:

compile fileTree(dir: 'libs', include: ['*.jar'])

这应该避免必须按名称调出每个罐子。

最后,我认为您的 proguard 配置中不需要任何 -libraryjars 行。

【讨论】:

  • 仍然收到Warning:there were 1 unresolved references to classes or interfaces. You may need to add missing library jars or update their versions. If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options.
  • 这只是一个警告。它仍然有效吗?如果没有,你能说出它缺少什么吗?
【解决方案2】:

在您的 build.gradle 中注释掉以下行:

compile files('libs/google-api-client-android2-1.10.3-beta-sources.jar')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 2017-03-03
    • 1970-01-01
    相关资源
    最近更新 更多