Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

java - 无法建立APK-Android Studio(Unable to build apk - android studio)

It's been a week now and we're unable to build the apk file for our andorid project.

(到现在已经一周了,我们无法为我们的andorid项目构建apk文件。)

The error that we're getting is related to the proguard(see the attached errors):

(我们得到的错误与proguard有关(请参阅随附的错误):)

Warning:there were 416 unresolved references to classes or interfaces.

(警告:有416个未解决的对类或接口的引用。)

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebug'.

(错误:任务':app:transformClassesAndResourcesWithProguardForDebug'的执行失败。)

java.io.IOException: Please correct the above warnings first.

(java.io.IOException:请首先更正以上警告。)

The project used to build before one of our recent commits.

(该项目曾经在我们最近提交的项目之一之前构建。)

So, when we checkout to that commit it works!

(因此,当我们签出该提交时,它就起作用了!)

We've tried everything available, related to this, on the stackoverflow/internet but nothing works!

(我们已经在stackoverflow / internet上尝试了与此相关的所有可用方法,但是没有任何效果!)

and the worst part is that it builds but just on one of our computers and we're unable to figure out why it doesn't work on other computers with the same version of the Android Studio.

(最糟糕的是它只能在我们的一台计算机上构建,而我们无法弄清楚为什么它不能在其他具有相同Android Studio版本的计算机上运行。)

We even tried to suppress the warnings by using :

(我们甚至尝试使用以下命令禁止显示警告:)

-dontwarn

(唐顿)

-keep class

(-保持课程)

So, in this case the build was successful but the app crashes.

(因此,在这种情况下,构建成功,但应用程序崩溃。)

Versions of the different components used :

(使用的不同组件的版本:)

Android Studio - 2.1.2

(Android Studio-2.1.2)

Proguard - 5.2.1

(Proguard-5.2.1)

buildToolsVersion 23.0.2

(buildToolsVersion 23.0.2)

Proguard errors

(Proguard错误)

These are the proguard rules that we're using for our project :

(这些是我们用于项目的proguard规则:)

-dontwarn com.github.siyamed.shapeimageview.path.parser.SvgToPath
-dontwarn com.google.android.gms.internal.zzhu
-dontwarn com.squareup.okhttp.**
-keep class com.opentok.** { *; }
-keep class org.webrtc.** { *; }

-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
-keep class org.acra.** { *; }
-keepclassmembers class com.paytm.pgsdk.PaytmWebView$PaytmJavaScriptInterface {
    public *;
}

##MoEngage proguard rules, src : http://docs.moengage.com/docs/android-configuring-proguard
-dontwarn com.google.android.gms.location.**
-dontwarn com.google.android.gms.gcm.**
-dontwarn com.google.android.gms.iid.**
-dontwarn okio.**

-keep class com.google.android.gms.gcm.** { *; }
-keep class com.google.android.gms.iid.** { *; }
-keep class com.google.android.gms.location.** { *; }
-keep class com.facebook.drawee.**{*;}
-dontwarn com.facebook.drawee.*

-keep class com.moe.pushlibrary.activities.** { *; }
-keep class com.moe.pushlibrary.internal.MoEService
-keep class com.moe.pushlibrary.GeofenceIntentService
-keep class com.moe.pushlibrary.InstallReceiver
-keep class com.moengage.push.MoEPushWorker
-keep class com.moe.pushlibrary.PushGcmBroadcastReceiver
-keep class com.moe.pushlibrary.providers.MoEProvider
-keep class com.moengage.receiver.MoEInstanceIDListener
-keep class com.moengage.worker.MoEGCMListenerService
-keep class com.moe.pushlibrary.models.** { *;}
-keep class com.moe.pushlibrary.internal.GeoTask
-keep class com.moengage.locationlibrarynew.LocationHandlerImpl

-dontwarn com.moengage.locationlibrarynew.LocationHandlerImpl
-dontwarn com.moe.pushlibrary.internal.GeoTask
-dontwarn com.moengage.receiver.*
-dontwarn com.moengage.worker.*
-dontwarn com.moengage.*
-keep class com.delight.**  { *; }

## for rx java
-dontwarn sun.misc.**

-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
   long producerIndex;
   long consumerIndex;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
  ask by Ashish Ranjan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you add some dependencies, there is a huge change that proguard will obsfucates the dependencies code.

(当您添加一些依赖项时,proguard会进行巨大的更改,从而混淆了依赖项代码。)

So instead using -dontwarn (which basically not warning you about some unresolved references) you should use -keep class .

(因此,而不是使用-dontwarn(基本上没有警告你一些未解决的引用),你应该使用-keep类 。)

Find the dependencies package name, then keep their class from being obsfucated by proguard.

(找到依赖程序包名称,然后防止其类被proguard混淆。)

-- UPDATED --

( - 更新 - )

From your log there are 2 dependencies that need to be resolved: facebook and android-shape-imageview.

(从您的日志中有2个需要解决的依赖项:facebook和android-shape-imageview。)

For facebook try adding this to your proguard:

(对于facebook,请尝试将其添加到您的proguard:)

-keep class com.facebook.** {
   *;
}

For shape-imageview:

(对于shape-imageview:)

-dontwarn android.support.v7.**
-keep class android.support.v7.** { ; }
-keep interface android.support.v7.* { ; }
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.**{ *; }

Read more at:

(阅读更多信息:)

  1. Android ProGuard settings for Facebook

    (Facebook的Android ProGuard设置)

  2. Anyone able to use this with proguard on?

    (有人可以在启用proguard的情况下使用它吗?)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...