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

x/mobile: Gradle version > 3.5.1 produces NullPointerException in GobindPlugin #21594

Closed
mtw-g opened this issue Aug 24, 2017 · 19 comments
Closed
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@mtw-g
Copy link

mtw-g commented Aug 24, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.8

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

linux (Ubuntu) / amd64

What did you do?

Android Studio 3.0 forced an update to Gradle plugin from 3.5.1 to 4.1x.

If possible, provide a recipe for reproducing the error.

Create an Android Studio project and add a module that uses the Gobind plugin (version 0.2.9)

Attempt to build the project

What did you expect to see?

Android Studio / Gradle should build an .aar from the Go source.

What did you see instead?

The plugin produces the following stacktrace:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':agent:gobind'.
    > Cannot get property 'classpath' on null object

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

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':agent:gobind'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.NullPointerException: Cannot get property 'classpath' on null object
at org.golang.mobile.GomobileTask.gomobile(GobindPlugin.groovy:219)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)

at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:731)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:705)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 27 more

@hyangah
Copy link
Contributor

hyangah commented Aug 24, 2017

I am a bit puzzled by the line numbers in the NullPointerException (GobindPlugin.groovy:219).
I assume the plugin worked before Android Studio upgrade.

@mtw-g
Copy link
Author

mtw-g commented Aug 24, 2017

That's almost correct - the plugin was working on Android Studio 3.0. What caused the breakage was being forced to update the Gradle version from 3.5.1 to 4.1.x

@Qheb
Copy link

Qheb commented Sep 22, 2017

Hello,

I am stuck on the same issue (NullPointerException at GobindPlugin.groovy:219), and this doesn't seem to be related with the Gradle version (I am reproducing it with Gradle 3.5).

What feels really strange is that I am using the gomobile plugin v0.2.9 and this is supposed to be fixed by @eliasnaur in this commit.
Moreover, I don't see how there could be any NullPointerException at line 219 in the current code:

if (javaCompile) { // <- This is line 219
    def classpath = project.files(javaCompile.classpath, javaCompile.destinationDir)
    cmd << "-classpath"
    cmd << classpath.join(File.pathSeparator)
}

Out of curiosity, I opened and decompiled my gobindPlugin-0.2.9.jar, and here is what I found:

Object classpath = var1[1].call(var1[2].callGroovyObjectGetProperty(this), var1[3].callGetProperty(this.javaCompile), var1[4].callGetProperty(this.javaCompile));
var1[5].call(cmd, "-classpath");
var1[6].call(cmd, var1[7].call(classpath, var1[8].callGetProperty(File.class)));
var1[9].call(cmd, "-o");
var1[10].call(cmd, var1[11].call(this.outputFile));
var1[12].call(cmd, "-target");

This really looks like the groovy code before the fix...

According to the history the 0.2.9 version is supposed to include the fix. But is there any possibility that the wrong source code version was shipped and tagged as 0.2.9 ?

@eliasnaur
Copy link
Contributor

/CC @hyangah

@charlescui
Copy link

charlescui commented Oct 28, 2017

same problem

gradle -v

------------------------------------------------------------
Gradle 2.14-rc-5
------------------------------------------------------------

Build time:   2016-06-07 13:58:17 UTC
Revision:     660f0c5357f2889208c85d20614904b397dfd47b

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_112 (Oracle Corporation 25.112-b16)
OS:           Mac OS X 10.12.5 x86_64

Erro info:

Error:Execution failed for task ':server:gobind'.
> Cannot get property 'classpath' on null object

@daudrain
Copy link

daudrain commented Nov 4, 2017

Same problem

------------------------------------------------------------
Gradle 2.10
------------------------------------------------------------

Build time:   2015-12-21 21:15:04 UTC
Build number: none
Revision:     276bdcded730f53aa8c11b479986aafa58e124a6

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Mac OS X 10.12.6 x86_64
18:16:37.296 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.NullPointerException: Cannot get property 'classpath' on null object
18:16:37.297 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.golang.mobile.GomobileTask.gomobile(GobindPlugin.groovy:219)
18:16:37.297 [ERROR] [org.gradle.BuildExceptionReporter] 	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)

@daudrain
Copy link

daudrain commented Nov 4, 2017

I've copied the plugin source to buildSrc directory of the Android bind example
cp -R misc/androidstudio/src/main example/bind/android/buildSrc/src/main

And the build succeeded.
As suggested by @Qheb , the published plugin may not contain the fix.

@bradfitz bradfitz changed the title Gradle version > 3.5.1 produces NullPointerException in GobindPlugin x/mobile: Gradle version > 3.5.1 produces NullPointerException in GobindPlugin Nov 4, 2017
@gopherbot gopherbot added this to the Unreleased milestone Nov 4, 2017
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Nov 4, 2017
@jeffallen
Copy link
Contributor

Hello @hyangah, this issue is making it impossible to build gomobile apps out of the box, which is pretty problematic... I was trying to sell some coworkers on gomobile, and the result was instead, "sorry, it seems like gomobile is not working and/or not supported right now".

CC @broady who might be able to find the right person for this after vacation.

@seebs
Copy link
Contributor

seebs commented Dec 29, 2017

Confirming that the plugin source copy fix worked. To be specific, copying from golang.org/x/mobile/misc/androidstudio/src/main to golang.org/x/mobile/example/bind/android/buildSrc/src/main. Also had to remove the existing plugin line specifying the gobind plugin, and add a new line, outside the plugins section, reading "apply plugin: 'org.golang.mobile.bind'".

Which got me to lint failures, papered over by adding the suggested don't-abort-on-failure stanza to app/build.gradle. (Does not work in build.gradle or hello/build.gradle.) And with that, I was able to get the thing to compile. Yayyy.

@rsc
Copy link
Contributor

rsc commented Jan 8, 2018

@jeffallen:

"sorry, it seems like gomobile is not working and/or not supported right now".

That's correct. As it says in golang.org/x/mobile/README, "The Go Mobile project is experimental. Use this at your own risk. While we are working hard to improve it, neither Google nor the Go team can provide end-user support." You have probably also noticed that there's very little activity in this repo recently from people at Google. We are focused on other things, although we're very grateful for the community work that has gone into keeping x/mobile working as we've stepped back, especially from @eliasnaur. While working on the compilers and standard library, we do continue to pay attention to keeping the mobile builders happy.

If there's some approval or something needed here, we can easily do that. It looks instead to me like code changes are needed but not yet written. CLs are welcome, but those of us at Google are not likely to get to this specific issue ourselves.

Thanks.

@jeffallen
Copy link
Contributor

@Qheb commented on 22 Sep 2017 that the plugin pushed to the distribution website does not match the code pushed to git. That is the correct diagnosis, and now what we need is someone from the Go team with the rights to push a new copy of the plugin to do that.

@hyangah
Copy link
Contributor

hyangah commented Jan 8, 2018

I am working on it to push but I am struggling with verifying the newly built plugin working with the newly installed android studio. Can anyone check if https://plugins.gradle.org/plugin/org.golang.mobile.bind.canary is working?

@hyangah
Copy link
Contributor

hyangah commented Jan 8, 2018

The latest error I got after updating the golang.org/x/mobile/example/bind/android

  • use the updated gradle (classpath 'com.android.tools.build:gradle:3.0.1' in build.gradle
  • hello/build.gradle to point to "org.golang.mobile.bind.canary" version "0.2.9.rc1"
Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform file 'hello.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform

Failed to transform file 'hello.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform
 > java.io.FileNotFoundException: /usr/local/google/home/hakim/go/src/golang.org/x/mobile/example/bind/android/hello/hello.aar (No such file or directory)
    > /usr/local/google/home/hakim/go/src/golang.org/x/mobile/example/bind/android/hello/hello.aar (No such file or directory)

The aar file the gobindplugin explects is not there.

@hyangah
Copy link
Contributor

hyangah commented Jan 8, 2018

Even though Android Studio is complaining about gradle project sync failure, build seems to be working. So I will just push it as 0.2.10 and hope the gradle sync failure warning issue seperately.

Many little bits in the bind example are outdated and need to be updated. I will file bugs for records. We need help to update the examples and the plugin code.

@gopherbot
Copy link

Change https://golang.org/cl/86775 mentions this issue: misc/androidstudio: update to 0.2.10

@gopherbot
Copy link

Change https://golang.org/cl/86795 mentions this issue: example: update android examples to use 0.2.10 plugin

@jeffallen
Copy link
Contributor

jeffallen commented Jan 9, 2018

In addition to changing the Go plugin to 0.2.10, I found that I needed to downgrade gradle to 2.10 to make it work, because of this error: https://stackoverflow.com/questions/37655814/gradle-sync-failed-unable-to-find-method

gopherbot pushed a commit to golang/mobile that referenced this issue Jan 9, 2018
0.2.9 was broken - for unknown reasons, the plugin was built on
top of stale sources.

Updates golang/go#21594

Plugin 0.2.10 was built with rev 50b7067 and this change.
  % docker run --rm -u root -v "$PWD":/home/gradle/project \
    -w /home/gradle/project gradle:latest \
    gradle publishPlugins

Gradle version is 4.0.1.

Change-Id: I146dc67cbad3c9945a2acdf4ac7993283725090a
Reviewed-on: https://go-review.googlesource.com/86775
Reviewed-by: Elias Naur <elias.naur@gmail.com>
gopherbot pushed a commit to golang/mobile that referenced this issue Jan 9, 2018
Also, modernize the build.gradle configurations
to work with recent Android plugin (>=3.0.0)

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

Update golang/go#21594

Change-Id: Ic2162db7367b60ad873149ab62767f36481fa80f
Reviewed-on: https://go-review.googlesource.com/86795
Reviewed-by: Elias Naur <elias.naur@gmail.com>
@eliasnaur
Copy link
Contributor

Is this still a problem with the plugin version 0.2.10? If not, please close this issue.

@eliasnaur
Copy link
Contributor

The plugin is gone from gomobile.

@golang golang locked and limited conversation to collaborators Mar 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

10 participants