Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError exception #65

Closed
javiersantos opened this issue Aug 18, 2015 · 19 comments
Closed

NoClassDefFoundError exception #65

javiersantos opened this issue Aug 18, 2015 · 19 comments

Comments

@javiersantos
Copy link
Contributor

This happens when pressing the button with the Intent.

final Intent chooserIntent = new Intent(context, DirectoryChooserActivity.class);
final DirectoryChooserConfig chooserConfig = DirectoryChooserConfig.builder()
         .newDirectoryName("Dir")
         .allowReadOnlyDirectory(false)
         .allowNewDirectoryNameModification(true)
         .build();
chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, chooserConfig);
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);

Logcat:

08-18 17:43:11.354  27433-27433/com.javiersantos.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.javiersantos.myapp, PID: 27433
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/gu/option/Option;
            at net.rdrei.android.dirchooser.DirectoryChooserFragment.<init>(DirectoryChooserFragment.java:60)
            at net.rdrei.android.dirchooser.DirectoryChooserFragment.newInstance(DirectoryChooserFragment.java:90)
            at net.rdrei.android.dirchooser.DirectoryChooserActivity.onCreate(DirectoryChooserActivity.java:38)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
            at android.app.ActivityThread.access$900(ActivityThread.java:154)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5289)
            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:904)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gu.option.Option" on path: DexPathList[[zip file "/data/app/com.javiersantos.myapp-2/base.apk"],nativeLibraryDirectories=[/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 net.rdrei.android.dirchooser.DirectoryChooserFragment.<init>(DirectoryChooserFragment.java:60)
            at net.rdrei.android.dirchooser.DirectoryChooserFragment.newInstance(DirectoryChooserFragment.java:90)
            at net.rdrei.android.dirchooser.DirectoryChooserActivity.onCreate(DirectoryChooserActivity.java:38)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
            at android.app.ActivityThread.access$900(ActivityThread.java:154)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5289)
            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:904)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
    Suppressed: java.lang.ClassNotFoundException: com.gu.option.Option
            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)
            ... 17 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
@passy
Copy link
Owner

passy commented Aug 18, 2015

Is that in the sample app?

@javiersantos
Copy link
Contributor Author

No, it happens using my own implementation in a Preference object on the PreferenceActivity class. I have not tested the sample app.

prefCustomPath = findPreference("prefCustomPath");

prefCustomPath.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                final Intent chooserIntent = new Intent(context, DirectoryChooserActivity.class);

                final DirectoryChooserConfig chooserConfig = DirectoryChooserConfig.builder()
                        .newDirectoryName("Dir")
                        .allowReadOnlyDirectory(false)
                        .allowNewDirectoryNameModification(true)
                        .build();

                chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, chooserConfig);
                startActivityForResult(chooserIntent, REQUEST_DIRECTORY);

                return false;
            }
        });

Thanks.

@javiersantos
Copy link
Contributor Author

Well, it fails when using the Fragment too (same Logcat).

prefCustomPath.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                final DirectoryChooserConfig chooserConfig = DirectoryChooserConfig.builder()
                        .newDirectoryName("Dir")
                        .allowReadOnlyDirectory(false)
                        .allowNewDirectoryNameModification(true)
                        .build();

                final DirectoryChooserFragment chooserDialog =                                                                 DirectoryChooserFragment.newInstance(chooserConfig);
                chooserDialog.show(getFragmentManager(), null);

                return false;
            }
});

@passy
Copy link
Owner

passy commented Aug 19, 2015

Yeah, this has nothing to do with the code there. Something with your build is broken, it seems that the transitive dependencies aren't included. It is declared as a dependency of the library though:

compile 'com.gu:option:1.3'

@javiersantos
Copy link
Contributor Author

Seems to be fixed when including transitive = true in gradle:

compile ('net.rdrei.android.dirchooser:library:3.0@aar') {
        transitive = true;
}

Then it tries to include com.gu:options, but gradle is not able to resolve the library.
screen shot 2015-08-19 at 11 06 19

@javiersantos
Copy link
Contributor Author

Fixed. I have included this lines in my own build.gradle

repositories {
    mavenCentral()
    maven { url 'http://guardian.github.com/maven/repo-releases' }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    ...
    compile ('net.rdrei.android.dirchooser:library:3.0@aar') { transitive = true; }
}

@passy
Copy link
Owner

passy commented Aug 19, 2015

👍 Thanks for documenting that!

@passy passy closed this as completed Aug 19, 2015
@rommex
Copy link

rommex commented Nov 3, 2015

After all the fixes by @javiersantos there is still a new error message:

Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 2

@javiersantos
Copy link
Contributor Author

What about adding this to your build.gradle @rommex?

defaultConfig {
    multiDexEnabled true
}

I think it happens because you have exceeded the 65K methods dex limit imposed by Android.

@rommex
Copy link

rommex commented Nov 3, 2015

@javiersantos thanks for your swift support. But your suggested insertions lead to some other nasty messages:

Error:duplicate files during packaging of APK D:\My Documents\AndroidStudioProjects\RayStoryBoard\app\build\outputs\apk\app-debug-unaligned.apk
Path in archive: META-INF/services/javax.annotation.processing.Processor
Origin 1: E:.gradle\caches\modules-2\files-2.1\com.google.auto.value\auto-value\1.1\f6951c141ea3e89c0f8b01da16834880a1ebf162\auto-value-1.1.jar
Origin 2: E:.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\6.1.0\63735f48b82bcd24cdd33821342428252eb1ca5a\butterknife-6.1.0.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}

@blackvvine
Copy link

I Don't know if it's just me or what, but I couldn't find a valid Maven repoistory on Guardian's "gu.options" github directory.
So I just downloaded Option 1.3 JAR file from:
http://guardian.github.io/maven/repo-releases/com/gu/option/1.3/option-1.3.jar
and everything's OK now.

@blackvvine
Copy link

[BASICS]
Just copy the JAR file to your app's "libs" folder and put the following in your app's "build.gradle" file:
compile files('libs/option-1.3.jar')

It's a great library BTW.

@ericbutler
Copy link

Another option for including co.gu.option is adding this to your build.gradle

dependencies {
compile 'com.gu:option:1.3'
}

@ghost
Copy link

ghost commented Feb 26, 2016

awesome work great

@popdeveloper
Copy link

Thanks. It worked by adding jar file.

@Phantast
Copy link

As this thread is quite long, here the summary of what solved it for me:

repositories {
    maven { url 'http://guardian.github.com/maven/repo-releases' }
}

dependencies {
    compile 'com.gu:option:1.3'
    compile 'net.rdrei.android.dirchooser:library:3.2@aar'
}

Hope it helps somebody else when checking this issue.

@micwallace
Copy link

Yep @Phantast's solution is the best one. adding transitive=true will grow your apk by ~800kb

@apacha
Copy link

apacha commented Feb 12, 2017

How about adding the resolution by @Phantast to the readme start-screen?

@Phantast
Copy link

It is quite some time ago since I faced this issue. Go ahead and add it. ;) I dont feel safe enough to make these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants