我已将 Eclipse 项目迁移到 Android Studio 。我在My Project中使用了三个模块并将 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 :
-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
所有事情最终都完成了,我也可以运行我的项目,但是当我尝试生成Sign Apk 时,它会给我带来错误:
我不知道它为什么会发生,因为它在Eclipse中完美运行。
任何帮助?
答案 0 :(得分:0)
首先,Android已经附带了Apache HTTPClient的实现。不要在另一个上添加依赖。
日志文件的底部显示失败的消息:
无法阅读[/libs/google-api-client-1.10.3-beta.jar](没有此类文件或目录)
您只需将libs中的所有jar作为编译依赖项添加到一行:
compile fileTree(dir: 'libs', include: ['*.jar'])
这应该避免不得不按名称召唤每个罐子。
最后,我不认为你在proguard配置中不需要任何-libraryjars行。
答案 1 :(得分:0)
在build.gradle中注释掉以下行:
compile files('libs/google-api-client-android2-1.10.3-beta-sources.jar')