相关疑难解决方法(0)

如何缩小代码 - dex中的65k方法限制

我有一个相当大的Android应用程序,它依赖于许多库项目.Android编译器对每个.dex文件有65536个方法的限制,我超过了这个数字.

当你达到方法限制时,你可以选择两种途径(至少我知道).

1)缩小你的代码

2)构建多个dex文件(参见此博文)

我调查了两个并试图找出导致我的方法计数变得如此之高的原因.Google Drive API占据了Guava依赖的最大块,超过12,000.Drive API v2的总库存超过23,000!

我想我的问题是,你认为我该怎么做?我应该删除Google云端硬盘集成作为我应用的功能吗?有没有办法缩小API(是的,我使用proguard)?我应该采用多重dex路由(看起来相当痛苦,尤其是处理第三方API)?

android guava dex google-drive-api android-multidex

90
推荐指数
6
解决办法
5万
查看次数

与Firebase相关的Google Play服务更新后,Android Google Cloud Messaging(GCM)令牌生成崩溃

在为Google Cloud Messaging(GCM)生成令牌时,我的Android应用程序今天开始崩溃.这种情况发生在Android的多个设备和版本上.我认为这可能与Google昨天在Google IO上宣布的新Firebase功能有关.

当这个开始发生时,我没有解决与GCM相关的代码,所以这是出乎意料的.如果我从Android系统设置中卸载Google Play服务更新,则该应用不会崩溃.一旦我重新安装最新版本,应用程序每次都会再次崩溃.

FATAL EXCEPTION: IntentService[MyGCMRegistrationIntentService]
Process: <my process>, PID: 26036
java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
    at com.google.android.gms.iid.zzd.zzeb(Unknown Source)
    at com.google.android.gms.iid.zzd.<init>(Unknown Source)
    at com.google.android.gms.iid.zzd.<init>(Unknown Source)
    at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
    at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
    at <package>.MyGCMRegistrationIntentService.onHandleIntent(MyGCMRegistrationIntentService.java:<line number>);
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.os.HandlerThread.run(HandlerThread.java:61)
Run Code Online (Sandbox Code Playgroud)

这是我的注册服务:

public class MyGCMRegistrationIntentService extends IntentService
{
    public static final String KEY_GCM_TOKEN = …
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-messaging

25
推荐指数
2
解决办法
2万
查看次数

java.lang.IllegalAccessError:Method'void android.support.v4.content

我在我的sdk中更新了playservice,我收到了这个错误.我无法访问GCM令牌.在更新sdk之前,我的项目完美运行.

我浪费了整整一天但没有找到任何解决方案.我尝试了这个, 但在这个依赖项中得到了错误com.google.android.gms:play-services-plus:9.0.0

这是我的logcat

Caused by: java.lang.IllegalAccessError: Method 'void android.support.v4.content.ContextCompat.<init>()' is inaccessible to class 'com.google.android.gms.iid.zzd' (declaration of 'com.google.android.gms.iid.zzd' appears in /data/data/com.hwindiapp.passenger/files/instant-run/dex/slice-com.google.android.gms-play-services-iid-9.0.0_b51865a18dbfbfb3651aaa54856c955adf1e354f-classes.dex)
   at com.google.android.gms.iid.zzd.zzeC(Unknown Source)
   at com.google.android.gms.iid.zzd.<init>(Unknown Source)
   at com.google.android.gms.iid.zzd.<init>(Unknown Source)
   at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
   at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
   at com.mainProfile.classFiles.RegisterFbLoginResCallBack$registerFBUser.processGCMID_user(RegisterFbLoginResCallBack.java:166)
   at com.mainProfile.classFiles.RegisterFbLoginResCallBack$registerFBUser.doInBackground(RegisterFbLoginResCallBack.java:219)
   at com.mainProfile.classFiles.RegisterFbLoginResCallBack$registerFBUser.doInBackground(RegisterFbLoginResCallBack.java:153)
   at android.os.AsyncTask$2.call(AsyncTask.java:292)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
   at java.lang.Thread.run(Thread.java:818) 
12-01 12:23:59.553 18157-18703/com.hwindiapp.passenger E/ACRA: Not adding buildConfig to log. Class Not found : com.VolleyLibFiles.BuildConfig. Please configure 'buildConfigClass' in your ACRA config
12-01 12:24:00.013 …
Run Code Online (Sandbox Code Playgroud)

android google-play-services build.gradle android-gradle-plugin

18
推荐指数
1
解决办法
2万
查看次数