android-已签名的APK中的ClassNotFoundException
作者:互联网
如果我在Android设备上安装并运行签名的APK,则会收到此错误.如果仅编译一个应用程序并直接在设备上运行,则不会出现此错误.
似乎丢失的Fragment在项目的代码中,而不是在任何外部库中.
我该如何调查该错误?我试图重新整理,清理项目等.如果在其中创建缺少的类,我能以某种方式在APK中找到吗?
hier是错误消息:
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.但是,以这种方式执行此操作是否是一种好习惯?
proguard-rules.pro现在是:
-dontobfuscate
-dontwarn org.apache.lang.**
-dontwarn com.google.common.**
-dontwarn org.joda.**
更新2:佩蒂回答了我的问题.
解决方法:
Proguard混淆了您至关重要的应用程序类别.
将以下行添加到您的proguard配置文件中,以使proguard不会与扩展Activity,Application,BroadcastReceiver,ContentProvider,Preference和&片段(支持和正常).
# 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
(如果您不愿意使用其中一些内容,则可以删除这些行)
然后删除此行
-dontobfuscate
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?
仅当您不关心有人在反编译您的应用程序时,这才是最佳实践.所以不行.通常是因为您想在生产/发布版本中尽可能地执行这样的任务.尤其是当您拥有应用内购买(IAP)或处理敏感数据时.
标签:android-gradle,android-studio,android 来源: https://codeday.me/bug/20191027/1945512.html