我过去几天一直在学习领域,今天我决定测试我在Android上使用Realm开发的应用程序,以实现向后兼容。
模拟器详细信息:
Name: Nexus_4_API_10_2.3.3
CPU/ABI: ARM (armeabi)
Path: /home/mush/.android/avd/Nexus_4_API_10_2.3.3.avd
Target: default [Default] (API level 10)
Skin: nexus_4
SD Card: 100M
hw.dPad: no
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: Nexus 4
vm.heapSize: 64
skin.dynamic: yes
hw.device.manufacturer: Google
hw.gps: yes
hw.initialOrientation: Portrait
image.androidVersion.api: 10
hw.audioInput: yes
image.sysdir.1: platforms/android-10/images/
tag.id: default
showDeviceFrame: yes
hw.camera.back: emulated
hw.mainKeys: no
应用程序在启动引用LoginActivity.java作为错误源时立即崩溃。 Logcat代码段:
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: _package_name_.sessions.LoginActivity
at _package_name_.SplashActivity.onCreate(SplashActivity.java:26)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
然后我继续注释掉调用LoginActivity.java的代码片段。
摘录:
//Check whether there's an active session first
sessionManager = new SessionManager(getApplicationContext());
if (sessionManager.isSessionActive()) {
//Session is active => Launch the MainActivity
Intent launchMainActivity = new Intent(getApplicationContext(), MainActivity.class);
startActivity(launchMainActivity);
} else {
//Session is inactive => Launch the LoginActivity
Intent launchLogin = new Intent(this, LoginActivity.class);
startActivity(launchLogin);
finish();
}
这并没有解决我的问题。相反,Logcat会在此时停止,应用程序会在我的启动屏幕上冻结。
logcat的:
D/RealmManager: Initializing Realm configuration.
D/dalvikvm: DexOpt: couldn't find static field
W/dalvikvm: VFY: unable to resolve static field 118 (SUPPORTED_ABIS) in Landroid/os/Build;
D/dalvikvm: VFY: replacing opcode 0x62 at 0x0006
D/dalvikvm: VFY: dead code 0x0008-000c in Lcom/getkeepsafe/relinker/SystemLibraryLoader;.supportedAbis ()[Ljava/lang/String;
D/dalvikvm: Trying to load lib /data/data/_package_name_/lib/librealm-jni.so 0x40513a90`
该应用程序在Android API级别24上运行得非常好。这是否意味着领域向后兼容?
这是我的build.gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "_package_name_"
minSdkVersion 10
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
// Exclude file to avoid
// Error: Duplicate files during packaging of APK
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'dk.ilios:realmfieldnameshelper:1.0.0'
compile 'io.realm:android-adapters:1.3.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
}
我做错了什么?我该如何纠正呢。我会感激任何帮助。 PS:似乎没有其他类似StackOverflow的问题。这个one接近了。