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
Closed

x/mobile: gobind Gradle plugin not working with Android Studio 3.0 #23307

pruflyos opened this issue Jan 2, 2018 · 7 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@pruflyos
Copy link

pruflyos 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 Android, iOS, and x/mobile label Jan 2, 2018
@laibulle
Copy link

laibulle commented Jan 3, 2018

I have the same problem. There is a workaround ?

@marni
Copy link

marni 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
Copy link

mtw-g 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
Copy link

Any updates?

@llitfkitfk
Copy link

Tips for manual installation with android studio 3.0

@gopherbot
Copy link

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

@eliasnaur
Copy link
Contributor

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
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
…sync

Suggestion from

golang/go#23307 (comment)

I've manually verified in Android Studio that removing the clean task
does fix the issue reported in golang/go#25290.

Fixes golang/go#25290.
Fixes golang/go#23307.

Change-Id: Ic1a8c240fc8e4c4aaf59977fd559dd221ff605b1
Reviewed-on: https://go-review.googlesource.com/112455
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
…sync

Suggestion from

golang/go#23307 (comment)

I've manually verified in Android Studio that removing the clean task
does fix the issue reported in golang/go#25290.

Fixes golang/go#25290.
Fixes golang/go#23307.

Change-Id: Ic1a8c240fc8e4c4aaf59977fd559dd221ff605b1
Reviewed-on: https://go-review.googlesource.com/112455
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
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

8 participants