这是一个非常奇怪的情况。我可以构建我的项目,清理和构建我的项目,甚至可以在具有调试模式的物理设备上运行。我还会在Google Analytics网页上获取所需的所有数据。
可悲的是,Android Studio没有生成发行版,.apk文件。我完全按照Add Analytics to Your Android App,官方教程,并搜索了很多答案,但确实存在问题。
我的build.gradle看起来像这样:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.comname.appname"
minSdkVersion 11
targetSdkVersion 23
versionCode 18
versionName "2.7"
}
buildTypes {
release {
minifyEnabled true
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/SalatCalculator.jar')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.google.android.gms:play-services-analytics:7.8.0'
}
以下是Gradle Build报告:
Information:Gradle tasks [:app:assembleRelease]
:app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:checkReleaseManifest
:app:preDebugBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72300Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42300Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase780Library UP-TO-DATE
:app:prepareReleaseDependencies
:app:compileReleaseAidl
:app:compileReleaseRenderscript
:app:generateReleaseBuildConfig
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets
:app:generateReleaseResValues UP-TO-DATE
:app:processReleaseGoogleServices
:app:generateReleaseResources
:app:mergeReleaseResources
:app:processReleaseManifest
:app:processReleaseResources
:app:generateReleaseSources
:app:processReleaseJavaRes UP-TO-DATE
:app:compileReleaseJavaWithJavac
Note: D:\D\AndroidStudio\AppName\app\src\main\java\com\comname\AppName\util\NotificationGenerator.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources
:app:proguardRelease
Warning:com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning:com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning:com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.methods.HttpGet
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.params.BasicHttpParams
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.methods.HttpGet
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.params.BasicHttpParams
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.internal.zzqt: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.tagmanager.zzby: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.Header
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.ClientProtocolException
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning:com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning:there were 61 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)
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:dexRelease
:app:validateExternalOverrideSigning
:app:packageRelease FAILED
Error:Execution failed for task ':app:packageRelease'.
> Unable to compute hash of D:\D\AndroidStudio\AppName\app\build\intermediates\classes-proguard\release\classes.jar
关于Note: D:\D\AndroidStudio\AppName\app\src\main\java\com\comname\AppName\util\NotificationGenerator.java uses or overrides a deprecated API.
,我已为此文件运行Lint,但未显示任何此类警告。
答案 0 :(得分:8)
问题与预测相关,您只在发布资料(minifyEnabled true
)上激活了程序。
您有两种选择:
禁用Proguard将此属性设置为false
。如果您要发布该应用,此选项实际上是不推荐。
向Proguard添加规则,以便与Google Analytics一起正常使用。应将此规则添加到文件proguard-rules.pro
中,这是一个示例:
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
有关Proguard的更多信息,请访问Android Developers Page和official project page
希望它有所帮助。
答案 1 :(得分:0)
还有一个解决方案,在谷歌解决问题之前我更喜欢这个解决方案。 您可以添加缺少的类,并且不必担心可能存在某些ClassNotFoundException。
所以只需在gradle配置中添加:
android {
useLibrary 'org.apache.http.legacy'
}