我正在开发一个曾经适用于API 23和22的项目,但是,一旦应用程序启动它就会发生崩溃(活动甚至无法加载) - 仅适用于API 22,对于API 23,它工作正常。日志对我没有多大帮助,而且我对可能导致此错误发生的想法没有用处。它抱怨的类是清单中定义的App类。以下是一些可能对分析有用的代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.gogame">
<application
android:name=".commons.infra.App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:installLocation="preferExternal"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme">
<meta-data
android:name="DATABASE"
android:value="gogame.db" />
<meta-data
android:name="VERSION"
android:value="27" />
<meta-data
android:name="QUERY_LOG"
android:value="false" />
<meta-data
android:name="DOMAIN_PACKAGE_NAME"
android:value="br.com.gogame.model" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".view.activities.ActivityLogin"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
public class App扩展com.orm.SugarApp {
private static App mApp = null;
private static MainComponent component;
private static RestTemplate mRequestService = new RestTemplate();
@Override
public void onCreate() {
super.onCreate();
mApp = this;
component = DaggerMainComponent
.builder()
.utilModule(new UtilModule(this))
.postmanModule(new PostmanModule(mRequestService))
.controllerModule(new ControllerModule())
.build();
Intent intent = new Intent(this, EventListener.class);
startService(intent);
}
public static Application getApplication() {
return mApp;
}
public static Context getContext() {
if (mApp == null) {
return new Application();
}
return mApp.getApplicationContext();
}
public static MainComponent getComponent() {
return component;
}
public static boolean isApplicationInBackground() {
boolean isInBackground = true;
ActivityManager am = (ActivityManager) mApp.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String activeProcess : processInfo.pkgList) {
if (activeProcess.equals(mApp.getApplicationContext().getPackageName())) {
isInBackground = false;
}
}
}
}
} else {
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if (componentInfo.getPackageName().equals(mApp.getApplicationContext().getPackageName())) {
isInBackground = false;
}
}
return isInBackground;
}
}
FATAL EXCEPTION: main
Process: br.com.gogame, PID: 31071 java.lang.RuntimeException: Unable to instantiate application br.com.gogame.commons.infra.App: java.lang.ClassNotFoundException: Didn't find class "br.com.gogame.commons.infra.App" on path: DexPathList[[zip file "/data/app/br.com.gogame-1/base.apk"],nativeLibraryDirectories=[/data/app/br.com.gogame-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:563)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4611)
at android.app.ActivityThread.access$1500(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.lang.ClassNotFoundException: Didn't find class "br.com.gogame.commons.infra.App" on path: DexPathList[[zip file "/data/app/br.com.gogame-1/base.apk"],nativeLibraryDirectories=[/data/app/br.com.gogame-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newApplication(Instrumentation.java:1003)
at android.app.LoadedApk.makeApplication(LoadedApk.java:558)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4611)
at android.app.ActivityThread.access$1500(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Suppressed: java.lang.ClassNotFoundException: br.com.gogame.commons.infra.App
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
apply plugin: 'com.android.application'
申请插件:'kotlin-android' apply plugin:'kotlin-android-extensions' 申请插件:'com.neenbedankt.android-apt'
android { compileSdkVersion 24 buildToolsVersion“23.0.2” compileOptions.incremental = false
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "br.com.gogame"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
renderscriptTargetApi 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
依赖{ 编译fileTree(包括:['* .jar'],dir:'libs') testCompile'junit:junit:4.12' testCompile'org.mockito:mockito-core:1.10.19'
// GOOGLE LIBRARIES
compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"
compile "com.android.support:cardview-v7:$support_version"
compile "com.android.support:design:$support_version"
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.guava:guava:18.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.dagger:dagger:2.1'
provided 'com.google.dagger:dagger-compiler:2.1'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.android.volley:volley:1.0.0'
// KOTLIN
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
// ANKO
compile "org.jetbrains.anko:anko-common:$anko_version"
compile "org.jetbrains.anko:anko-sdk15:$anko_version"
compile "org.jetbrains.anko:anko-support-v4:$anko_version"
compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
// APACHE LIBRARIES
compile 'org.apache.httpcomponents:httpmime:4.0-alpha3'
// OWN THIRD LIBRARIES
compile 'br.com.instachat:emoji-library:1.0.8'
compile 'br.com.edsilfer:kiwi:1.0.16'
// THIRD PART LIBRARIES
compile 'com.mikhaellopez:circularimageview:2.0.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.vajro:MaterialDesignLibrary:1.6'
compile 'com.ogaclejapan.smarttablayout:library:1.6.0@aar'
compile 'com.github.rey5137:material:1.2.2'
compile 'com.appyvet:materialrangebar:1.3'
compile 'com.github.afollestad.material-dialogs:core:0.8.5.6@aar'
compile 'com.wang.avi:library:1.0.5'
compile 'com.nineoldandroids:library:2.4.0'
compile "com.mikepenz:iconics-core:2.6.6@aar"
compile 'com.mikepenz:fastadapter:1.5.6@aar'
compile 'com.mikepenz:aboutlibraries:5.6.6@aar'
compile 'com.wdullaer:materialdatetimepicker:2.3.0'
compile 'javax.inject:javax.inject:1'
compile 'com.github.satyan:sugar:1.5'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.15'
compile 'com.yalantis:ucrop:1.5.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'org.adw.library:discrete-seekbar:1.0.1'
compile 'com.wang.avi:library:1.0.5'
compile 'jp.wasabeef:blurry:2.0.2'
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32@aar'
compile 'com.github.d-max:spots-dialog:0.4@aar'
provided 'javax.annotation:jsr250-api:1.0'
}
buildscript { 存储库{ jcenter() } 依赖{ classpath“org.jetbrains.kotlin:kotlin-android-extensions:$ kotlin_version” } }
申请插件:'com.google.gms.google-services'
答案 0 :(得分:0)
你要踢自己......
清单包名称中的缺少开头的br应该是: br.com.gogame.commons.infra.App
你反而将它作为.com.gogame.commons.infra.App,它将无效,因此找不到类错误