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

model error #17

Closed
jiqimaogou opened this issue Oct 25, 2014 · 14 comments
Closed

model error #17

jiqimaogou opened this issue Oct 25, 2014 · 14 comments

Comments

@jiqimaogou
Copy link

when I define a model, and then run the app, it has errors.
Error:Execution failed for task ':app:compileDebugJava'.

java.lang.NoClassDefFoundError: android/content/ContentValues

i Use api 21.

@jiqimaogou
Copy link
Author

Caused by: java.lang.NoClassDefFoundError: android/content/ContentValues
at ollie.internal.codegen.writer.ModelAdapterWriter.writeImports(ModelAdapterWriter.java:105)
at ollie.internal.codegen.writer.ModelAdapterWriter.writeSource(ModelAdapterWriter.java:88)
at ollie.internal.codegen.writer.ModelAdapterWriter.writeSource(ModelAdapterWriter.java:41)
at ollie.internal.codegen.step.ModelAdapterStep.process(ModelAdapterStep.java:71)
at ollie.internal.codegen.OllieProcessor.process(OllieProcessor.java:76)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
... 66 more

I work in android studio.

@wontondon
Copy link

@jiqimaogou I ran into the same issue. It looks like the annotation processor needs the android.jar at compile time. I included the android.jar as a 'provided' dependency. I'm not sure if there is a better way to get around this issue. I would have assumed that I wouldn't need to explicitly do this, but I'm not sure how the android gradle plugin lifecycle works with ollie.

I ended up with the following build.gradle file which loads my android sdk path from local.properties and adds the android jar a provided dependency. I got the idea from the ollie build file.

//... removed for brevity

// Find my sdk path
def Properties props = new Properties()
props.load(new FileInputStream(file('../local.properties')))

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.0'

    //... removed for brevity

    defaultConfig {
        minSdkVersion 16 // Can't use try-resource blocks unless min at least 19
        targetSdkVersion 21 // roboelectric issue needs 18
        versionCode 1
        versionName "1.0"
    }
    // ... remove for brevity
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:21.0.0'
    compile 'com.android.support:appcompat-v7:21.0.0'
    ... // removed for brevity
    provided files("${props["sdk.dir"]}/platforms/android-21/android.jar")  // provide android.jar for ollie
}

@carltonwhitehead
Copy link

Thanks for sharing your workaround @donaldlittlepie. It worked for me.

@carltonwhitehead
Copy link

I spoke too soon. I switched back on proguard via minifyEnabled true and now I'm getting the following error:

Execution failed for task ':app:proguardDebug'.
> java.io.IOException: The same input jar [/path/to/android-sdk/platforms/android-21/android.jar] is specified twice.

When I remove the provided files("${props["sdk.dir"]}/platforms/android-21/android.jar") line and leave minifyEnabled true, it reverts to the original error of this issue report.

@wontondon
Copy link

@carltonwhitehead sorry about that. I wasn't at the point of trying to proguard my files.

@Rainer-Lang
Copy link

and then I get:
warning: File for type 'ollie.AdapterHolderImpl' created in the last round will not be subject to annotation processing.

@pardom-zz
Copy link
Owner

Don't worry about that warning. It just means that the class which Ollie created won't be processed, i.e. no recursive processing. I'll look in to the above and making sure that dependencies are self-contained.

@Rainer-Lang
Copy link

Thanks Michael.
Now I can test ollie. :-)

@pardom-zz
Copy link
Owner

Can you guys try the latest snapshot and see if things have improved?

@carltonwhitehead
Copy link

Relevant lines from my build.gradle:

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
    compile 'com.michaelpardo:ollie:0.3.0-SNAPSHOT'
    provided 'com.michaelpardo:ollie-compiler:0.3.0-SNAPSHOT'
}

When I do ./gradlew clean assembleDebug, I still get the same error.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:_compileDebugJava'.
> java.lang.NoClassDefFoundError: android/content/ContentValues

Is 0.3.0-SNAPSHOT the correct version? I picked it based on https://github.com/pardom/ollie/blob/575e12830878a86cc602d38245781a9c66dbb443/gradle.properties

EDIT: I just went through https://oss.sonatype.org/content/repositories/snapshots/com/michaelpardo/ollie/0.3.0-SNAPSHOT/ and compared the md5 for the jar with the timestamp from today with the one in my local gradle cache, and it was a match. Pretty sure this means whatever you changed didn't solve it. Is it working for you locally? Perhaps there's an environment configuration coming into play here.

EDIT 2: Same error with both ollie-0.3.0-20141211.150943-6.jar and ollie-0.3.0-20141211.161608-7.jar

@pardom-zz
Copy link
Owner

Yeah, that's it. I'm seeing that on my end too. Provided dependencies aren't really supported natively by Gradle so I'm trying a few things to get this working. I'll post an update when I figure it out.

@pardom-zz
Copy link
Owner

Just a note: I made a change (removed LruCache) which requires support-v4, so you'll need to add that jar too, until I figure out this issue (if you're using the snapshot).

@pardom-zz
Copy link
Owner

Okay, this has been fixed and pushed to snapshots. The problem was that the compiler was using Android classes to safely get import class names by type. I switched these out for strings and removed the Android dependency.

@carltonwhitehead
Copy link

Thanks @pardom

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

5 participants