gpt4 book ai didi

java - 安卓工作室 : NoClassDefFoundError exception on runtime with Java Library Module

转载 作者:行者123 更新时间:2023-11-30 03:10:43 24 4
gpt4 key购买 nike

我在运行我的应用程序时遇到问题。问题似乎是,当在运行时引用这些模块中的类时,android studio 0.4.2 中的任何 java 库模块都会创建 NoClassDefFoundError。该应用程序编译时没有错误或警告。

我的项目包含这 4 个模块:

  1. SimpleMessenger(Java 库模块)
  2. Nfc.Benchmark.Domain(Java 库模块)
  3. Nfc.Benchmark.View(Android 库模块)
  4. Nfc.Benchmark.View.Gui(安卓应用模块)

当应用程序正在运行并引用 simplemessenger.MessengerService 类时,执行失败并出现 NoClassDefFoundError 异常。

堆栈跟踪:

01-09 14:40:13.819    1152-1152/no.as.gold.nfc.benchmark.view.gui E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: no.as.gold.simplemessenger.MessengerService
at no.as.gold.nfc.benchmark.view.BaseTagFragment.registerMessageListeners(BaseTagFragment.java:37)
at no.as.gold.nfc.benchmark.view.BaseTagFragment.<init>(BaseTagFragment.java:26)
at no.as.gold.nfc.benchmark.view.ReadTagFragment.<init>(ReadTagFragment.java:27)
at no.as.gold.nfc.benchmark.view.gui.activities.MainActivity$SectionsPagerAdapter.<init>(MainActivity.java:317)
at no.as.gold.nfc.benchmark.view.gui.activities.MainActivity.refreshActionBar(MainActivity.java:194)
at no.as.gold.nfc.benchmark.view.gui.activities.MainActivity.onCreate(MainActivity.java:72)
at android.app.Activity.performCreate(Activity.java:5255)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2049)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4940)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)

抛出异常的源代码(MessengerService.Default.Register(...)):

public abstract class BaseTagFragment extends Fragment {
//region fields
private Tag mTag;
//endregion

//region Constructors
/**
* Constructor that initiates the BaseTagFragment
*/
public BaseTagFragment() {
// Add message listeners
registerMessageListeners();
}
//endregion

//region Properties
public Tag GetTag() {return mTag;}
//endregion

//region Private methods
private void registerMessageListeners() {
// Extract tags from new intents
MessengerService.Default.Register(this, NewIntentMessage.class, new MessageHandler<NewIntentMessage>() {

@Override
public void handler(NewIntentMessage msg) {
Tag tag = msg.Intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if(tag != null) mTag = tag;
}
});
}
//endregion

在升级到 Android Studio 0.4.2 之前,我删除了 .gradle 缓存,如下所述:https://stackoverflow.com/questions/19521764/android-studio-0-3-java-library-module-doesnt-work在升级之前效果很好。现在我不知所措,我已经搜索了几个小时但没有找到任何有用的东西。

非常感谢任何帮助!

修改后的 build.gradle,将 SimpleMessenger.jar 添加到 libs\文件夹(这没有解决问题):

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'

repositories {
mavenCentral()
}

android {
compileSdkVersion 17
buildToolsVersion '17.0.0'

defaultConfig {
minSdkVersion 16
targetSdkVersion 16
}
release {
runProguard false
proguardFile 'proguard-rules.txt'
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}

dependencies {
compile project(':Nfc.Communication')
compile 'org.apache.commons:commons-lang3:3.1'
compile 'com.google.android:support-v4:r6'
compile project(':Nfc.Benchmark.Domain')
//compile project(':SimpleMessenger')
compile files('libs/SimpleMessenger.jar')
}

最佳答案

此问题已在 Android Studio 0.4.4 :D ( http://tools.android.com/recent/androidstudio044released ) 中解决

关于java - 安卓工作室 : NoClassDefFoundError exception on runtime with Java Library Module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21022279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com