我正在尝试生成一个签名的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>appbuildintermediatesmulti-dexreleasecomponentClasses.jar] must be specified after an input jar, or it will be empty.
下面是我的应用级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
仍然没有运气
在你的trace中有一些信息——
警告:有4个未解析的类或接口引用。您可能需要添加缺失的库jar或更新它们的版本。如果您的代码在没有丢失类的情况下运行良好,则可以进行抑制带有'- donwarn '选项的警告。(http://proguard.sourceforge.net/manual/troubleshooting.html unresolvedclass)
至少你的部分问题是AndroidHttpClient
在API 23中被删除,并且至少有一个库依赖于它。你有三个选择。
1)您可以在build.gradle
文件中包含以下内容。其中包括您的apk中的遗留库。参见Apache HTTP客户端删除。
android {
useLibrary 'org.apache.http.legacy'
}
2)您可以降低目标并将sdk编译为22而不是23。这应该允许您编译,或者至少解决AndroidHttpClient
问题,直到库更新到不需要它。
3)你可以添加-dontwarn
命令到你的proguard文件来抑制警告以获得构建。正如文档中所指出的,如果您不确定可以安全地忽略警告,那么这可能是危险的。我不确定忽略删除HttpClient
和相关类所产生的警告是否安全。在M上运行时可能会导致不稳定的构建,但对于L及以下版本应该是安全的,因为这些类存在于该API级别的设备上。
补充道:对于同样挣扎的人,请记住,您必须将依赖项中的builToolsVersion
和com.android.support
降低到22.0.1
。
这是个很容易解决的问题。当你正在开发一款应用,并在中途更新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'
}
}
}
希望能有所帮助