我正在尝试生成已签名的apk,并且日志一直显示以下错误:
:app:compileReleaseJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources
:app:collectReleaseMultiDexComponents
:app:proguardRelease
Warning:com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning:com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.ironsource.mobilcore.j: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification
Warning:com.mopub.volley.toolbox.HttpClientStack: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.mopub.volley.toolbox.HttpClientStack$HttpPatch
Warning:com.mopub.volley.toolbox.HttpClientStack$HttpPatch: can't find referenced method 'void setURI(java.net.URI)' in program class com.mopub.volley.toolbox.HttpClientStack$HttpPatch
Warning:com.mopub.volley.toolbox.Volley: can't find referenced class android.net.http.AndroidHttpClient
Warning:there were 4 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.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 4 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning:there were 1 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Exception while processing task
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:473)
at proguard.ProGuard.initialize(ProGuard.java:233)
at proguard.ProGuard.execute(ProGuard.java:98)
at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
at com.android.builder.tasks.Job.runTask(Job.java:48)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
at java.lang.Thread.run(Thread.java:745)
:app:shrinkReleaseMultiDexComponents FAILED
Error:Execution failed for task ':app:shrinkReleaseMultiDexComponents'.
> java.io.IOException: The output jar [<project_path>\app\build\intermediates\multi-dex\release\componentClasses.jar] must be specified after an input jar, or it will be empty.
以下是我的 app-level build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.my.app"
minSdkVersion 14
targetSdkVersion 23
versionCode 25
versionName "2.5"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
}
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.2.0'
compile 'me.dm7.barcodescanner:zxing:1.7.2'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.scottyab:secure-preferences-lib:0.1.3'
compile 'com.soundcloud.android:android-crop:1.0.0@aar'
compile('com.afollestad.material-dialogs:core:0.8.1.0@aar') {
transitive = true
}
compile('com.mopub:mopub-sdk:3.13.0@aar') {
transitive = true
}
compile project(':android-support-v4-preferencefragment')
compile project(':circular_progress_bar')
compile files('libs/mobilecore_V1.1.jar')
compile files('libs/libAdapterSDKMoPub.jar')
compile files('libs/adcolony.jar')
}
我的顶级build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
我尝试使用其他版本的gradle,例如1.4.0-beta1', 1.4.0-beta2
,1.3.1
仍然没有运气。
答案 0 :(得分:3)
跟踪中有一些信息 -
警告:有4个未解析的类或接口引用。 您可能需要添加缺少的库jar或更新其版本。 如果您的代码工作正常而没有丢失的类,则可以禁止 '-dontwarn'选项的警告。 (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
至少部分问题是在API 23中删除了AndroidHttpClient
,并且至少有一个库依赖于它。你有三个选择。
1)您可以在build.gradle
文件中包含以下内容。其中包括apk中的旧版库。请参阅Apache HTTP Client Removal。
android {
useLibrary 'org.apache.http.legacy'
}
2)您可以降低目标并将sdk编译为22而不是23.这应该允许您编译,或者至少解决AndroidHttpClient
问题,直到库更新为不需要它为止。
3)您可以向proguard文件添加-dontwarn
命令,以禁止发出警告。如文档中所述,如果您不确定可以安全地忽略警告,则这可能很危险。我不确定是否忽略因删除HttpClient
及相关类而产生的警告是否安全。在M上运行时可能会导致构建不稳定,但对于L及更低版本应该是安全的,因为这些类存在于该API级别的设备上。
增加:
对于遇到同样困难的人,请记住,您必须将依赖关系中的builToolsVersion
和com.android.support
降低到22.0.1
。
答案 1 :(得分:0)
这是一个非常容易解决的问题。当您开发应用程序时,问题就会出现,而在中间的某个地方,您会更新SDK。这很好但是你不知道你的项目的gradle配置应该是最新的。所以,只需创建一个新项目,然后在项目中查看classpath
我的com.android.tools.build:gradle:1.3.1
,但现在新项目类路径为classpath 'com.android.tools.build:gradle:1.5.0'
。要考虑的另一件事是compileSdkVersion
,buildToolsVersion
,targetSdkVersion
。您还应该检查您的库版本是否是最新的。您可以通过简单地打开SDK管理器找到他们的版本。
所以把它包起来:
这是您的项目gradle应该更新的内容:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0' //update this section to the lates gradle core available
}
}
这是gradle模块级文件中应该更新的部分:
android {
compileSdkVersion 23 // update this one
buildToolsVersion "23.0.2" // update this one
defaultConfig {
applicationId "ranjbar.hadi.something"
minSdkVersion 14
targetSdkVersion 23 // update this one
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
希望这会有所帮助