我目前正在使用 Android Studio 开发一个 Android 应用.目前,该应用程序在 Lollipop 设备上完美启动,但由于在预棒棒糖设备上出现 ClassNotFoundException
而在启动时崩溃(我已经在 ICS 上进行了测试,但它失败了).
I'm currently developping an Android app using Android Studio. Currently, the app is launching perfectly on Lollipop devices, but crashes at launch due to a ClassNotFoundException
on pre-lollipop devices (i've tested on ICS and it fail).
缺少的类在运行时总是来自外部库.
The missing class is always from an external librairies at runtime.
这是 gradle 文件:
Here's the gradle file :
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
defaultConfig {
applicationId 'com.kappsports.kapp10'
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName '1.0.0'
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
shrinkResources true
}
}
lintOptions {
abortOnError false
}
dexOptions {
incremental true
javaMaxHeapSize '4g'
}
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', exclude: 'android-support-v4.jar', include: '*.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
transitive = true;
}
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile 'com.github.johnpersano:supertoasts:1.3.4@aar'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup:otto:1.3.5'
compile 'com.makeramen:roundedimageview:1.3.0'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.malinskiy:superrecyclerview:1.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'org.buraktamturk:loadingview:1.0.0@aar'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
compile 'net.danlew:android.joda:2.8.2'
//noinspection GradleCompatible
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.google.android.gms:play-services:7.5.0'
//noinspection GradleCompatible
compile 'com.android.support:recyclerview-v7:22.2.1'
}
这是 logcat 输出的一部分:
Here is a shunk of logcat output :
> 09-06 23:25:58.414 27436-27436/? W/dalvikvm﹕ Link of class
> 'Lio/fabric/sdk/android/InitializationTask;' failed 09-06 23:25:58.414
> 27436-27436/? E/dalvikvm﹕ Could not find class
> 'io.fabric.sdk.android.InitializationTask', referenced from method
> io.fabric.sdk.android.Kit.<init> 09-06 23:25:58.414 27436-27436/?
> W/dalvikvm﹕ VFY: unable to resolve new-instance 8228
> (Lio/fabric/sdk/android/InitializationTask;) in
> Lio/fabric/sdk/android/Kit; 09-06 23:25:58.414 27436-27436/?
> D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0003 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Unable to resolve superclass of
> Lio/fabric/sdk/android/InitializationTask; (8269) 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Link of class
> 'Lio/fabric/sdk/android/InitializationTask;' failed 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Unable to resolve superclass of
> Lio/fabric/sdk/android/InitializationTask; (8269) 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Link of class
> 'Lio/fabric/sdk/android/InitializationTask;' failed 09-06 23:25:58.414
> 27436-27436/? I/dalvikvm﹕ Could not find method
> io.fabric.sdk.android.InitializationTask.getDependencies, referenced
> from method io.fabric.sdk.android.Kit.getDependencies 09-06
> 23:25:58.414 27436-27436/? W/dalvikvm﹕ VFY: unable to resolve virtual
> method 57413:
> Lio/fabric/sdk/android/InitializationTask;.getDependencies
> ()Ljava/util/Collection; 09-06 23:25:58.414 27436-27436/? D/dalvikvm﹕
> VFY: replacing opcode 0x6e at 0x0002 09-06 23:25:58.414 27436-27436/?
> W/dalvikvm﹕ VFY: unable to find class referenced in signature
> (Lio/fabric/sdk/android/services/common/IdManager;) 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Unable to resolve superclass of
> Lio/fabric/sdk/android/InitializationTask; (8269) 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Link of class
> 'Lio/fabric/sdk/android/InitializationTask;' failed 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Unable to resolve superclass of
> Lio/fabric/sdk/android/InitializationTask; (8269) 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ Link of class
> 'Lio/fabric/sdk/android/InitializationTask;' failed 09-06 23:25:58.414
> 27436-27436/? I/dalvikvm﹕ Could not find method
> io.fabric.sdk.android.InitializationTask.executeOnExecutor, referenced
> from method io.fabric.sdk.android.Kit.initialize 09-06 23:25:58.414
> 27436-27436/? W/dalvikvm﹕ VFY: unable to resolve virtual method 57412:
> Lio/fabric/sdk/android/InitializationTask;.executeOnExecutor
> (Ljava/util/concurrent/ExecutorService;[Ljava/lang/Object;)V 09-06
> 23:25:58.414 27436-27436/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at
> 0x0011 09-06 23:25:58.414 27436-27436/? W/dalvikvm﹕ VFY: unable to
> find class referenced in signature
> (Lio/fabric/sdk/android/services/common/IdManager;) 09-06 23:25:58.419
> 27436-27436/? W/dalvikvm﹕ Unable to resolve superclass of
> Lio/fabric/sdk/android/InitializationTask; (8269) 09-06 23:25:58.419
> 27436-27436/? W/dalvikvm﹕ Link of class
> 'Lio/fabric/sdk/android/InitializationTask;' failed 09-06 23:25:58.419
> 27436-27436/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0xe03e at
> 0x05 in Lio/fabric/sdk/android/Kit;.<init> 09-06 23:25:58.419
> 27436-27436/? D/AndroidRuntime﹕ Shutting down VM 09-06 23:25:58.419
> 27436-27436/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught
> exception (group=0x41bfb700) 09-06 23:25:58.419 27436-27436/?
> E/AndroidRuntime﹕ FATAL EXCEPTION: main
> java.lang.NoClassDefFoundError: io.fabric.sdk.android.services.common.ExecutorUtils
> at com.crashlytics.android.core.CrashlyticsCore.<init>(CrashlyticsCore.java:205)
> at com.crashlytics.android.core.CrashlyticsCore$Builder.build(CrashlyticsCore.java:189)
> at com.kappsports.kapp10.Kapp10Application.onCreate(Kapp10Application.java:53)
> at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
> at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4684)
> at android.app.ActivityThread.access$1400(ActivityThread.java:159)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
> at android.os.Handler.dispatchMessage(Handler.java:99)
> at android.os.Looper.loop(Looper.java:176)
> at android.app.ActivityThread.main(ActivityThread.java:5419)
> at java.lang.reflect.Method.invokeNative(Native Method)
> at java.lang.reflect.Method.invoke(Method.java:525)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
> at dalvik.system.NativeStart.main(Native Method) 09-06 23:25:58.424 2346-2891/? I/ActivityManager﹕ Notify an
> ApplicationCrash
我目前没有解决方案.任何有关这方面的线索将不胜感激.
I'm currently out of solution for now. Any clue about that would be appreciated.
谢谢,问候.
1) 为您的应用添加多索引支持:
1) Add multidex support to your app:
compile 'com.android.support:multidex:1.0.1'
2) 将您的应用程序设置为 MultiDexApplication
.选择以下选项之一:
2) Set your application as a MultiDexApplication
. Select one of the options below:
这是android的MultiDexApplication
类的源码:
This is the source code of android's MultiDexApplication
class:
public class MultiDexApplication extends Application {
public MultiDexApplication() {
}
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
选项 1) 您可以从 MultiDexApplication
扩展您的自定义应用程序:
Option 1) You can extend your custom application from MultiDexApplication
:
public class MyApplication extends MultiDexApplication {
// Your application implementation here
}
选项 2) 您可以从默认的 Application
类扩展您的自定义应用程序,然后您需要在 调用
方法:MultiDex.install
attachBaseContext(Context base)
Option 2) You can extend your custom application from default Application
class, then you need to call MultiDex.install
at attachBaseContext(Context base)
method:
public class MyApplication extends Application {
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
// Your application implementation here
}
选项 3) 如果您没有任何自定义应用程序并且您不想要任何应用程序,只需将您的应用程序名称(在 AndroidManifest.xml 中)设置为 MultiDexApplication:
Option 3) If you don't have any custom application and you don't want any, simply set your application name (at AndroidManifest.xml) to MultiDexApplication:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
注意:如果您使用的是自定义应用程序类(参见 Option1 和 Option2),则必须已经设置了 application
标签的 android:name
到您的自定义应用程序类.
Note: If you are using a custom application class (see Option1 and Option2), application
tag's android:name
must already be set to your custom application class.
3) 将 multiDexEnabled true
设置添加到您的 build.gradle 文件中:
3) Add multiDexEnabled true
setting to your build.gradle file:
defaultConfig {
// Other settings here
multiDexEnabled true
}
更多信息.
这篇关于Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!