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

Cannot cast object ':app' with class 'java.lang.String' to class 'org.gradle.api.Project' #5

Closed
s0nerik opened this issue Nov 1, 2014 · 30 comments
Assignees
Labels

Comments

@s0nerik
Copy link

s0nerik commented Nov 1, 2014

Hi! I'm getting
Error:(13, 0) Cannot cast object ':app' with class 'java.lang.String' to class 'org.gradle.api.Project'
Here's build.gradle for tester project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'se.centril.robospock:gradle-plugin-robospock:0.2.1'
    }
}

apply plugin: 'robospock'

robospock {
    android = ':app'
}

build.gradle for main project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath CLASSPATH
    }
}
apply plugin: 'com.android.application'

repositories {
    flatDir {
        dirs '../libs'
    }
    mavenCentral()
}

android {
    compileSdkVersion COMPILE_SDK
    buildToolsVersion BUILD_TOOLS
    defaultConfig {
        minSdkVersion MIN_SDK
        targetSdkVersion TARGET_SDK
        versionCode 4
        versionName '0.7'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(dir: '../libs', include: '*.jar')
    compile 'uk.me.lewisdeane.ldialogs:ldialogs@aar'
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.android.support:support-v4:19.+'
    compile 'com.google.code.gson:gson:+'
    compile project(':libs:UnifiedPreference')
    compile project(':libs:android-stackblur')
    compile project(':libs:Fontify')
    compile project(':libs:FadingActionBar')
    compile project(':libs:ExoPlayer')
    compile 'com.nineoldandroids:library:+'
    compile 'com.jakewharton:butterknife:+'
    compile 'com.squareup:otto:+'
    compile 'com.squareup.okio:okio:+'

    compile ('com.fizz-buzz:fb-android-dagger:1.0.3'){
        exclude group: 'com.google.android', module: 'support-v4'
    }

    compile 'com.squareup.dagger:dagger:1.2.2'
    compile 'com.squareup.dagger:dagger-compiler:1.2.2'

    compile 'com.loopj.android:android-async-http:1.4.5'
    compile 'com.squareup.okhttp:okhttp:+'
    compile 'com.squareup.okhttp:okhttp-urlconnection:+'
    compile 'com.squareup.mimecraft:mimecraft:+'
    compile 'com.koushikdutta.ion:ion:1.+'
    compile 'org.java-websocket:Java-WebSocket:1.3.0'
    //    compile 'com.viewpagerindicator:library:2.4.1'
    compile('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
        exclude group: 'com.google.android', module: 'support-v4'
    }

    compile 'com.android.support:recyclerview-v7:21.+'
    compile 'org.projectlombok:lombok:1.14.8'
}

Also, I'm using constants from gradle.properties. Here they are:

TARGET_SDK = 21
COMPILE_SDK = android-21
MIN_SDK = 10
BUILD_TOOLS = 21
CLASSPATH = com.android.tools.build:gradle:0.14.+
@s0nerik s0nerik closed this as completed Nov 1, 2014
@s0nerik s0nerik reopened this Nov 1, 2014
@Centril
Copy link
Owner

Centril commented Nov 2, 2014

Do you have a stack-trace perhaps?

@s0nerik
Copy link
Author

s0nerik commented Nov 2, 2014

Yeah. Here it is:

* What went wrong:           
A problem occurred evaluating project ':app-test'.
> Cannot cast object ':app' with class 'java.lang.String' to class 'org.gradle.api.Project'

* Try:                       
Run with --info or --debug option to get more log output.

* Exception is:              
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app-test'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:190)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
        at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:521)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:82)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ':app' with class 'java.lang.String' to class 'org.gradle.api.Project'
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:392)
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:306)
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:227)
        at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2652)
        at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3702)
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.setProperty(BeanDynamicObject.java:187)
        at org.gradle.api.internal.BeanDynamicObject.setProperty(BeanDynamicObject.java:112)
        at org.gradle.api.internal.CompositeDynamicObject.setProperty(CompositeDynamicObject.java:101)
        at se.centril.robospock.RoboSpockConfiguration_Decorated.setProperty(Unknown Source)
        at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:191)
        at groovy.lang.Closure.setPropertyTryThese(Closure.java:388)
        at groovy.lang.Closure.setPropertyDelegateFirst(Closure.java:378)
        at groovy.lang.Closure.setProperty(Closure.java:359)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setGroovyObjectProperty(ScriptBytecodeAdapter.java:528)
        at build_2dko3h92kaq2sb6eql92ifk3v2$_run_closure1.doCall(/home/sonerik/Projects/LWM/app-test/build.gradle:13)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:278)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
        at groovy.lang.Closure.call(Closure.java:423)
        at groovy.lang.Closure.call(Closure.java:439)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:59)
        at org.gradle.api.internal.plugins.ExtensionsStorage$ExtensionHolder.configure(ExtensionsStorage.java:145)
        at org.gradle.api.internal.plugins.ExtensionsStorage.configureExtension(ExtensionsStorage.java:69)
        at org.gradle.api.internal.plugins.DefaultConvention$ExtensionsDynamicObject.invokeMethod(DefaultConvention.java:207)
        at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
        at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79)
        at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:933)
        at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1256)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1209)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
        at build_2dko3h92kaq2sb6eql92ifk3v2.run(/home/sonerik/Projects/LWM/app-test/build.gradle:12)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
        ... 42 more          


BUILD FAILED                 

@Centril Centril added the bug label Nov 3, 2014
@Centril Centril self-assigned this Nov 3, 2014
@Centril
Copy link
Owner

Centril commented Nov 3, 2014

I'll take a look at it today - didn't have any time yesterday, sorry!
From the looks of the stacktrace, I'm seeing that RoboSpockConfiguration.setAndroid is not being called for some weird reason... some groovy language weirdness :/

Btw - as a temporary fix, if your android project has the path :app and your test project has the path :app-test, you don't need to specify the name of the android project at all.

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

At a closer look, it seems like the gradle decorated extension is interfering and not passing the public void setAndroid( String t ) to RoboSpockConfiguration, however the void setAndroid( Project t ) version works...

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Indeed, removing

robospock {
    android = ':app'
}

fixes a problem with gradle sync. But then when I try to run a test, I get

Error:Gradle: A problem occurred configuring project ':app-test'.
> RoboSpock: could not guess project and no project found in robospock.android, please set it!

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

What is the exact path of your Android project and your test project?

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Here's a screenshot with files hierarchy:

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

Strange, I'll look into it, meanwhile, try:

robospock {
    android = project( ':app' )
}

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

I've did like this before. It makes gradle sync work too. But when I try to run test it says:

Error:(13, 0) Gradle: A problem occurred evaluating project ':app-test'.
> project ':app' is not an android project

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

Try adding this to the root build.gradle

groovy
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'se.centril.robospock:gradle-plugin-robospock:0.2.1'
}
}


For some strange reason, when I add it to the root project, it works, but not otherwise...

Also, try to apply the plugin to the android project instead right after you have applied the android plugin and don't add the above to the buildscript of the root and see what happens...

Does any of this work?

I'll have to fix this so you don't get this trouble...

I created a basic sample repo that works for me, try it... https://github.com/Centril/test-robospock-plugin

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

I have exactly the same problem with project you suggested:

Error:(20, 0) Gradle: A problem occurred evaluating project ':app-test'.
> project ':app' is not an android project

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Also, none of your suggestions helped.

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Maybe it will be helpful to note that I use Android Studio 0.9.1

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

What happens if you run gradle via command line?

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

when I

./gradlew assemble

it gives me

:app-test:compileJava UP-TO-DATE                                                       
:app-test:compileGroovy UP-TO-DATE      
:app-test:processResources UP-TO-DATE      
:app-test:classes UP-TO-DATE      
:app-test:jar UP-TO-DATE      
:app-test:assemble UP-TO-DATE      

BUILD SUCCESSFUL

but when I try to run a test I get this messages:

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

What about: ./gradlew robospock ?
It seems like the problem is on Android Studio side...

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Looks like you're right...
It gives me

[sonerik@sonerik-desktop app-test]$ /home/sonerik/Projects/test-robospock-plugin/gradlew robospock
:app-test:compileJava UP-TO-DATE                                                       
:app-test:compileGroovy UP-TO-DATE     
:app-test:processResources UP-TO-DATE     
:app-test:classes UP-TO-DATE      
:app:preBuild                 
:app:preDebugBuild                 
:app:checkDebugManifest                 
:app:prepareDebugDependencies                 
:app:compileDebugAidl UP-TO-DATE      
:app:compileDebugRenderscript UP-TO-DATE      
:app:generateDebugBuildConfig UP-TO-DATE      
:app:generateDebugAssets UP-TO-DATE      
:app:mergeDebugAssets UP-TO-DATE      
:app:generateDebugResValues UP-TO-DATE      
:app:generateDebugResources UP-TO-DATE      
:app:mergeDebugResources UP-TO-DATE      
:app:processDebugManifest UP-TO-DATE      
:app:robospockCopyDebugManifest UP-TO-DATE      
:app:processDebugResources UP-TO-DATE      
:app:generateDebugSources UP-TO-DATE      
:app:compileDebugJava UP-TO-DATE      
:app:robospock_zip2jar UP-TO-DATE      
:app-test:compileTestJava UP-TO-DATE      
:app-test:compileTestGroovy UP-TO-DATE                                                       
:app-test:processTestResources UP-TO-DATE      
:app-test:testClasses UP-TO-DATE      
:app-test:robospock                                                                  
Running test: test should have a ListView(com.example.AppActivitySpecification)

BUILD SUCCESSFUL

Total time: 11.273 secs

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

So now the question is how can I run it under Android Studio (or have some output from Spock). Maybe you can suggest something?

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

Ah, well, that's good at least...
I don't know much about how the gradle plugin for Android Studio / Intellij Ultimate works unfortunately.

Spock/Gradle however generates its results in: app-test\build\reports\tests\index.html.
If there are failures, then it will be displayed during the gradle build and output to command line directly with the current setup... But for more details about the failures, you have to check the test report.

If possible, I'll try to fix the part about not being able to set a string on robospock.android property - otherwise I'll remove that part of DSL and then you have to use

robospock {
    android = project( ':app' )
}

instead. I've created a stackoverflow question about it... http://stackoverflow.com/questions/26730867/gradle-overload-extension-setter

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Wow! That's what I looked for! Thanks! I think, you can close this issue, 'cause it seems like it's not really related to the plugin itself.
BTW, thanks for ability to use Spock to test Android apps =)

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

Glad it worked =)
I guess I'll close the issue once I can determine what I should do with the original part of your question about the GroovyCastException - I'm edging towards removing the String setters and only keeping the Project ones...

As a convenience, I recommend applying the plugin to the android project and putting the testing files in app/src/test/... as specified here: https://github.com/Centril/gradle-plugin-robospock#applying-from-an-android-project-since-020

Btw, I only deserve part of the credit... I didn't create RoboSpock, I only made this gradle plugin ^^
Robospock itself is here: https://github.com/Polidea/RoboSpock

@pjakubczyk
Copy link

@s0nerik thanks for investing your time helping @Centril

The integration issue is really a killer when somebody wants to use Robospock/Robolectric ...

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Yeah, I know. But the original plugin didn't worked for me, giving

Could not find property 'configurationContainer'

I'll try to put tests inside app/src/test and let you know what I'll get soon.

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

Putting tests into app/src/test gives me a following error:

Error:Cannot increment beyond the total of: 2

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

In gradle command line? That happened to me in Intellij too while developing the plugin... Their plugin seems to be quite crappy to be honest.

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

No, in command line ./gradlew assemble goes well.

@s0nerik
Copy link
Author

s0nerik commented Nov 4, 2014

I think, I gonna try to report this issue with Error:Cannot increment beyond the total of: 2 as a bug for IntelliJ, but I don't really know how can I formulate the actual issue.

@Centril
Copy link
Owner

Centril commented Nov 4, 2014

Perhaps you can provide a link to this issue? It might have to do with ProjectBuilder which is used when applying on android project and putting the test sources in app/src/test/...

@Centril
Copy link
Owner

Centril commented Nov 5, 2014

Luke Daley from Gradleware informed me that the first part about GroovyCastException is a limitation of the Groovy language: https://jira.codehaus.org/browse/GROOVY-2500

So I have no choice but to remove the setXYZ( String xyz ) setters.

@bluesliverx
Copy link
Contributor

I submitted the cannot increment error as a bug against android studio: https://code.google.com/p/android/issues/detail?id=79009&thanks=79009&ts=1415554661.

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

No branches or pull requests

4 participants