签名apk中的ClassNotFoundException

时间:2015-12-16 20:33:02

标签: android android-studio android-gradle

如果我在Android设备上安装并运行已签名的APK,则会出现此错误。如果我只是编译应用程序并直接在设备上运行,则不会出现此错误。

片段,似乎缺少的是在我的项目代码中,而不是在任何外部库中。

我该如何调查该错误?我试图重新制作,清理项目等。如果在那里创建缺失的类,我能以某种方式找到APK吗?

hier是错误消息:

rbind.fill()

这是我的E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{qua.com.bix/qua.com.bix.main.MainActivity}: android.support.v4.app.q: Unable to instantiate fragment qua.com.bix.main.MainLoadingFragment: make sure class name exists, is public, and has an empty constructor that is public at Android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295) .... .... Caused by: android.support.v4.app.q: Unable to instantiate fragment qua.com.bix.main.MainLoadingFragment: make sure class name exists, is public, and has an empty constructor that is public .... .... Caused by: java.lang.ClassNotFoundException: Didn't find class "qua.com.bix.main.MainLoadingFragment" on path: /data/app/qua.com.bix-1.apk at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64) at java.lang.ClassLoader.loadClass(ClassLoader.java:501) at java.lang.ClassLoader.loadClass(ClassLoader.java:461) at android.support.v4.app.o.a(Unknown Source)  at android.support.v4.app.o.a(Unknown Source) 

build.gradle

更新:目前有什么帮助,禁用了proguard,同时将apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "qua.com.bix" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' } dexOptions{ incremental true javaMaxHeapSize "4g" } useLibrary 'org.apache.http.legacy' } dependencies { compile 'com.android.support:multidex:1.0.1' compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.quadriq.qlib:qlib@aar' compile 'com.google.code.gson:gson:2.4' compile 'com.google.guava:guava:18.0' compile 'com.google.code.findbugs:jsr305:2.0.2' compile 'com.google.android.gms:play-services:8.3.0' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' compile 'com.koushikdutta.ion:ion:2.+' compile 'joda-time:joda-time:2.9.1' compile 'com.github.michaelye.easydialog:easydialog:1.1' } 添加到-dontobfuscate。但以这种方式做这件事是一种好习惯吗?

proguard-rules.pro现在是:

proguard-rules.pro

更新2 :petey回答了我的问题。

1 个答案:

答案 0 :(得分:4)

Proguard正在混淆你的重要应用类。

将以下行添加到proguard配置文件中,以便proguard不会混淆应用程序的扩展ActivityApplicationBroadcastReceiverContentProvider,{{ 1}},& Preference(支持和正常)。

Fragment

(如果您不使用其中一些可以随意删除这些行)

然后删除此行

# Base Android exclusions, required for proper function of various components
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
  

现在有所帮助,禁用了proguard,还添加了-dontobfuscate   到proguard-rules.pro。但在这方面做这件事是一种好习惯   方式是什么?

如果您不在乎是否有人反编译您的应用程序,那么这只是最佳做法。所以不行。主要是因为您希望在生产/发布版本上尽可能地创建类似的任务。特别是如果您有In App Purchasing(IAP)或处理敏感数据。