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: gobind Gradle plugin not working with Android Studio 3.0 #23307

Closed
pruflyos opened this issue Jan 2, 2018 · 7 comments

Comments

Projects
None yet
8 participants
@pruflyos
Copy link

commented Jan 2, 2018

Please answer these questions before submitting your issue. Thanks!

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

go1.8.1 linux/amd64

Does this issue reproduce with the latest release?

Don't know, this is the latest release available in Debian Stretch (backports).

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

linux/amd64 (Debian Stretch)

What did you do?

I tried to run the mobile/example/bind/android example with AndroidStudio 3.0.1, which uses Gradle 4.1 and version 3.0.1 of the Android Gradle build plugin.

What did you expect to see?

A successful Gradle project sync.

What did you see instead?

Gradle project sync failed.

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: /home/user/gocode/src/golang.org/x/mobile/example/bind/android/hello/hello.aar (No such file or directory)
    > /home/user/gocode/src/golang.org/x/mobile/example/bind/android/hello/hello.aar (No such file or directory)

Even if I create the hello.aar file manually via command line using gomobile bind and copy it to the above location, it get's deleted again as soon as I run the Gradle sync in Android Studio.

@bradfitz bradfitz changed the title gobind Gradle plugin not working with Android Studio 3.0 x/mobile: gobind Gradle plugin not working with Android Studio 3.0 Jan 2, 2018

@gopherbot gopherbot added this to the Unreleased milestone Jan 2, 2018

@gopherbot gopherbot added the mobile label Jan 2, 2018

@laibulle

This comment has been minimized.

Copy link

commented Jan 3, 2018

I have the same problem. There is a workaround ?

@marni

This comment has been minimized.

Copy link

commented Feb 3, 2018

Same problem here.

My current workaround is to build the .aar file manually with gomobile bind, then import .aar module into the Android Studio project (New/New Module/Import .jar/.aar). In other words, I do not use the plugin at all, just manually import the .aar module into the project, and make the project dependent on it.

You can test it with bind/hello example. Delete the "hello" folder with its gradle file from the android project first, then build the hello.aar manually, in the original location of the hello.go package, import the .aar into the Android Studio project, and make the project dependent on the newly added module.

@mtw-g

This comment has been minimized.

Copy link

commented Feb 23, 2018

After a bunch of blind poking and prodding in GobindPlugin.groovy, I have something that works. I don't know if it's the right way to fix this bug, but I am able to sync and build my project again.

Specifically, I moved the 'clean task':

    Task cleanTask = project.tasks.create("clean", {
        project.delete(project.name+".aar")
    })

from the GobindPlugin.apply method to BindTask.run method.

To anyone who is more knowledgeable about Gradle plugins, is this is a reasonable way to fix the issue?

Here's a diff for reference:

--- ./agent/external-deps/src/golang.org/x/mobile/misc/androidstudio/src/main/groovy/org/golang/mobile/GobindPlugin.groovy      2017-10-30 14:09:08.182858589 -0700
+++ ./buildSrc/src/main/groovy/org/golang/mobile/GobindPlugin.groovy    2018-02-23 14:47:11.943655069 -0800
@@ -66,9 +66,11 @@
                        null,
                        gomobileTask))
 
+        /*
                Task cleanTask = project.tasks.create("clean", {
                        project.delete(project.name+".aar")
                })
+        */
        }
 
        private static void handleVariant(Project project, def variant) {
@@ -137,7 +139,9 @@
                        // fallback to ANDROID_HOME
                        androidHome = System.getenv("ANDROID_HOME")
                }

+        Task cleanTask = project.tasks.create("clean", {
+            project.delete(project.name+".aar")
+        })
                project.exec {
                        executable(exe)
@wilyarti

This comment has been minimized.

Copy link

commented Apr 23, 2018

Any updates?

@llitfkitfk

This comment has been minimized.

Copy link

commented May 9, 2018

Tips for manual installation with android studio 3.0

@gopherbot

This comment has been minimized.

Copy link

commented May 9, 2018

Change https://golang.org/cl/112455 mentions this issue: misc/androidstudio: drop the clean task to fix Android Studio gradle sync

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented May 9, 2018

The CL should fix the issue. Note that only gradle sync fails; running a gomobile project from Android Studio does work.

@golang golang locked and limited conversation to collaborators May 9, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.