签署的APK中的ClassNotFoundException [英] ClassNotFoundException in signed apk
问题描述
如果我在Android设备上安装并运行签名的APK,则会收到此错误.如果我只是编译一个应用程序并直接在设备上运行,则不会出现此错误.
I got this error if I install and run a signed APK at my android device. This error does not come up if I just compile an app and run directly at device.
似乎丢失的片段是在项目的代码中,而不是在任何外部库中.
The Fragment, that seems to be missing is in my code in the project, not in any external library.
我该如何调查该错误?我尝试重新整理,清理项目等.如果在其中创建缺少的类,我能以某种方式在APK中找到吗?
How could I investigate that error? i tried to rebuld, clean project etc.. Could I somehow find in APK if missing classes are created there?
hier是错误消息:
hier is the error message:
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
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'
}
更新:暂时有所帮助的是,禁用了proguard,并且还在proguard-rules.pro
中添加了-dontobfuscate
.但是,以这种方式执行此操作是否是一种好习惯?
Update: What helped for now, is disabling proguard, also adding -dontobfuscate
to proguard-rules.pro
. But is it a good practice to do this in that way?
proguard-rules.pro现在是:
the proguard-rules.pro is now:
-dontobfuscate
-dontwarn org.apache.lang.**
-dontwarn com.google.common.**
-dontwarn org.joda.**
更新2 :petey回答了我的问题.
Update 2: petey answered my question.
推荐答案
Proguard混淆了您至关重要的应用程序类.
Proguard is obfuscating your vital app classes.
将以下行添加到您的proguard配置文件中,以使proguard不会与扩展Activity
,Application
,BroadcastReceiver
,ContentProvider
,Preference
和& Fragment
(支持和常规).
add the following lines to your proguard config file so that proguard will not mess with your application's classes that extend Activity
, Application
, BroadcastReceiver
, ContentProvider
, Preference
, & Fragment
(support and normal).
# 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
(如果您不愿意使用其中一些内容来删除这些行)
(if you arent using some of these feel free to remove those lines)
然后删除此行
-dontobfuscate
目前有所帮助的是,禁用了proguard,还添加了-dontobfuscate 到proguard-rules.pro.但这是一个好习惯吗 方式吗?
What helped for now, is disabling proguard, also adding -dontobfuscate to proguard-rules.pro. But is it a good practice to do this in that way?
这是最佳实践,如果您不关心有人在反编译您的应用程序.所以不行.通常是因为您想在生产/发布版本中尽可能地执行这样的任务.尤其是如果您拥有In App Purchasing(IAP)或处理敏感数据.
It is only best practice if you do not care if someone decompiles your application. So, no. Mostly because you want to make a task like that as hard as possible on your production/release builds. Especially if you have In App Purchasing(IAP) or handle sensitive data.
这篇关于签署的APK中的ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!