GVKun编程网logo

切换到Android Studio 2.0后使用Dagger 2时出现NoClassDefFoundError(android studio切换界面)

8

关于切换到AndroidStudio2.0后使用Dagger2时出现NoClassDefFoundError和androidstudio切换界面的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多

关于切换到Android Studio 2.0后使用Dagger 2时出现NoClassDefFoundErrorandroid studio切换界面的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android Dex问题造成的NoClassDefFoundError、android studio java.lang.NoClassDefFoundError Gson、Android Studio java.lang.NoClassDefFoundError:android.support.v4.app.NavUtilsJB、Android Studio Volley = NoClassDefFound?等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

切换到Android Studio 2.0后使用Dagger 2时出现NoClassDefFoundError(android studio切换界面)

切换到Android Studio 2.0后使用Dagger 2时出现NoClassDefFoundError(android studio切换界面)

在升级到 Android Studio 2.0之前,我可以使用Dagger 2没问题.现在我得到一个NoClassDefFoundError这让我关闭了一天以上,我正在寻求帮助.

似乎Gradle不能用我的AppModule类,即使它很清楚它在我的项目中.我甚至包括set multiDexEnabled true,即使我的项目只有几个文件.

我在网上找到的所有内容都表明您可以单击要导入的库. Android Studio没有这样的奢侈品.

任何帮助将不胜感激,你将获得我不懈的忠诚.

04-21 17:26:54.006 7875-7875/com.androidtitan.spotscoreapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.androidtitan.spotscoreapp,PID: 7875
@R_301_3865@.NoClassDefFoundError: com.androidtitan.spotscoreapp.main.injection.AppModule_ProvidesApplicationFactory
at com.androidtitan.spotscoreapp.main.injection.DaggerAppComponent.initialize(DaggerAppComponent.java:31)
at com.androidtitan.spotscoreapp.main.injection.DaggerAppComponent.<init>(DaggerAppComponent.java:23)
at com.androidtitan.spotscoreapp.main.injection.DaggerAppComponent.<init>(DaggerAppComponent.java:0)
at com.androidtitan.spotscoreapp.main.injection.DaggerAppComponent$Builder.build(DaggerAppComponent.java:66)
at com.androidtitan.spotscoreapp.App.onCreate(App.java:28)
at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:326)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5010)
at android.app.ActivityThread.access$1600(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5835)
at @R_301_3865@.reflect.Method.invoke(Native Method)
at @R_301_3865@.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)


package com.androidtitan.spotscoreapp.main.injection;

import android.app.Application;
import android.content.Context;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

的AppModule

@Module
public class AppModule {
private static Application application;

public AppModule(Application application) {
    this.application = application;
}

@Provides @Singleton
Application providesApplication() {
    return application;
}

@Provides @Singleton
Context providesApplicationContext() {
    return application.getBaseContext();
}
}

AppComponent

package com.androidtitan.spotscoreapp.main.injection;

import android.app.Application;
import android.content.Context;

import com.androidtitan.spotscoreapp.main.ui.activity.LoginActivity;
import com.androidtitan.spotscoreapp.main.ui.fragment.LoginFragment;
import com.androidtitan.spotscoreapp.main.ui.fragment.SignUpFragment;

import javax.inject.Singleton;

import dagger.Component;

@Singleton
@Component(
    modules = { AppModule.class,LoginPresenterModule.class }
)
public interface AppComponent {
Application getApplication();
Context getApplicationContext();

void inject(LoginFragment activity);
}

应用扩展了应用

import android.app.Application;
import android.support.multidex.MultiDexApplication;

import com.androidtitan.spotscoreapp.main.injection.AppComponent;
import com.androidtitan.spotscoreapp.main.injection.AppModule;
import com.androidtitan.spotscoreapp.main.injection.DaggerAppComponent;
import com.firebase.client.Firebase;

import timber.log.Timber;

public class App extends Application {

private static AppComponent appComponent;

@Override
public void onCreate() {
    super.onCreate();

    Firebase.setAndroidContext(this);

    appComponent = DaggerAppComponent.builder()
            .appModule(new AppModule(this))
            .build();

    if (BuildConfig.DEBUG) {
        Timber.plant(new Timber.DebugTree());
    }

}

public static AppComponent getAppComponent(){
    return appComponent;
}
}

的build.gradle(模块:APP)

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion 23
buildToolsversion "24.0.0 rc1"

defaultConfig {
    applicationId "com.androidtitan.spotscoreapp"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true


}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
    }
}

packagingOptions {
    exclude 'meta-inf/DEPENDENCIES.txt'
    exclude 'meta-inf/NOTICE'
    exclude 'meta-inf/NOTICE.txt'
    exclude 'meta-inf/LICENSE'
    exclude 'meta-inf/LICENSE.txt'
}
}

dependencies {
compile filetree(include: ['*.jar'],dir: 'libs')
testCompile 'junit:junit:4.12'
apt 'com.google.dagger:dagger-compiler:2.0'
compile 'com.android.support:multidex:1.0.0'

provided 'com.google.dagger:dagger-compiler:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.jakewharton.timber:timber:4.1.2'
compile 'com.android.support:design:23.3.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.firebase:firebase-client-android:2.3.1'
}

的build.gradle(项目:spotscoreapp)

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.0.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

AndroidManifest

`

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:name=".App"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".main.ui.activity.LoginActivity"
        android:label="@string/title_activity_login"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity android:name=".main.ui.activity.MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

`

解决方法

我有一个非常类似的问题,并通过在Android Studio中做很常见的事情来解决它.你基本上需要

使缓存无效,然后清理项目

你知道,Dagger2在编译时会生成很多代码,有时会出现问题,特别是如果你使用Android Studio 2.0提供的Instant Run

Android Dex问题造成的NoClassDefFoundError

Android Dex问题造成的NoClassDefFoundError

前言:

 

NoClassDefFoundError和ClassNotFoundException相比,前者是类加载后直接抛出(一般属于VM抛出),后者一般是加载时抛出(一般属于ClassLoader抛出),很明显前者是在避免了ClassNotFoundException异常之后抛出的,直白一点就是,前者意味着类是存在的。

显然NoClassDefFoundError这种错误的根源,“链接“和”初始化“阶段发生,当然以初始化为主的比较多。 

 

最终原因时:该类被虚拟机标记为无效的类。

 

原因:

为什么该类被提前标记为无效类呢?
 
(1)dexopt 类扫描 (Android 5.0之前版本特有的一类NoClassDefFoundError)
dexopt会扫描被该类A引用的所有的其他类是否存在,如果不存在,则其他类会被标记未无效类。
 
这种情况往往发生在使用multidex对main-dex分包后,由于没有找到类,会被标记为无效的类
 
 
(2)初始化时发生了异常
W/dalvikvm: Unable to resolve superclass of Lcom/tencent/bugly/beta/Beta; (68)
W/dalvikvm: Link of class ''Lcom/tencent/bugly/beta/Beta;'' failed
W/dalvikvm: VFY: unable to resolve static field 154 (autoCheckUpgrade) in Lcom/tencent/bugly/beta/Beta;
D/dalvikvm: VFY: replacing opcode 0x6a at 0x0002
W/dalvikvm: Unable to resolve superclass of Lcom/tencent/bugly/crashreport/CrashReport$UserStrategy; (66)
W/dalvikvm: Link of class ''Lcom/tencent/bugly/crashreport/CrashReport$UserStrategy;'' failed
D/dalvikvm: DexOpt: unable to opt direct call 0x0165 at 0x12 in Lcom/pitaya/buckettool/BucketApplication;.initBugly

 

 

 

android studio java.lang.NoClassDefFoundError Gson

android studio java.lang.NoClassDefFoundError Gson

我做了一个很新的项目.我通过谷歌将gson库添加到我的projects / libs目录并将其添加为库.我还将它添加到我的build.gradle中

compile files('libs/gson-2.2.4.jar')

所以现在一切看起来都不错,Android Studio没有任何错误,任何地方都没有红色下划线.我可以建立它并试一试.

但后来我遇到了这个错误:

java.lang.NoClassDefFoundError: com.google.gson.Gson

我在调试器中可以看到.事情是我已经添加它并且android studio可以看到但是来构建它给了我所有这些类型的问题.

我究竟做错了什么?

解决方法:

有同样的问题.我做的是gradle clean,然后从控制台用gradle构建我的项目.在我的build.gradle中,gson依赖关系如下所示:

dependencies {
    compile 'com.google.code.gson:gson:2.2.4'
}

Android Studio java.lang.NoClassDefFoundError:android.support.v4.app.NavUtilsJB

Android Studio java.lang.NoClassDefFoundError:android.support.v4.app.NavUtilsJB

这是我的错误日志与Android Studio 1.0.2实现

02-03 13:05:23.831    8385-8385/com.******.*******E/AndroidRuntime﹕     FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB
        at   android.support.v4.app.NavUtils$NavUtilsImplJB.getParentActivityName(NavUtils    .java:125)
        at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:302)
        at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:281)
        at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:142)
        at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
        at com..******.*******.****.ActivityWelcome.onCreate(ActivityWelcome.java:33)
        at android.app.Activity.performCreate(Activity.java:5104)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
        at android.app.ActivityThread.access$600(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        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:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)

组态

buildToolsVersion "21.1.2"
android SDK TOOLS"24.0.2"
multidex enabled
predexLibraries =false
incremental = true
jumboMode = false
  dependencies {
    compile fileTree(dir: 'libs',include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:support-v4:21.0.3@aar'
    compile 'com.android.support:appcompat-v7:21.0.3@aar'
    compile project(':ViewPagerIndicator')
    compile('de.keyboardsurfer.android.widget:crouton:1.8.4@aar') {
        exclude group: 'com.google.android',module: 'support-v4'
    }
    compile 'org.java-websocket:Java-WebSocket:1.3.0'
}

如何解决这个错误?gradlew清洁无济于事。构建文件夹删除也不起作用。Android Studio编译时未显示任何错误。

Android Studio Volley = NoClassDefFound?

Android Studio Volley = NoClassDefFound?

好吧,我决定同时试用 Android的Volley网络库和新的Android Studio IDE.但是,我遇到了一些问题.

我构建了volley.jar,将其复制到我的libs文件夹中以获取新项目,编辑build.gradle以包含volley,并在我的主要活动中设置静态ImageLoader和RequestQueue.但是,当我将应用程序加载到模拟器(4.2)上时,我最终得到了

E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: com.android.volley.toolBox.Volley

调用Volley时如下:

        queue = Volley.newRequestQueue(this);

Gradle编辑以支持库:

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/volley.jar')
}

有人介意我指向正确的方向吗?

解决方法

Exception java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker

在这里找到了修复.

基本上,打开命令提示符(或终端)并导航到项目目录.在Windows上使用以下命令:

对于Windows用户:
gradlew.bat干净

对于mac用户输入:./ gradlew clean

然后重新加载Android Studio,然后重试!

我们今天的关于切换到Android Studio 2.0后使用Dagger 2时出现NoClassDefFoundErrorandroid studio切换界面的分享就到这里,谢谢您的阅读,如果想了解更多关于Android Dex问题造成的NoClassDefFoundError、android studio java.lang.NoClassDefFoundError Gson、Android Studio java.lang.NoClassDefFoundError:android.support.v4.app.NavUtilsJB、Android Studio Volley = NoClassDefFound?的相关信息,可以在本站进行搜索。

本文标签: