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: proguard strips generated proxy classes from AAR #30251

Closed
halseth opened this issue Feb 15, 2019 · 4 comments
Closed

x/mobile: proguard strips generated proxy classes from AAR #30251

halseth opened this issue Feb 15, 2019 · 4 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@halseth
Copy link

halseth commented Feb 15, 2019

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

$ go version
go version go1.11.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/johan/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/johan/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/johan/golang/src/github.com/lightningnetwork/lnd/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kq/3436m_v11sg0l7zqtmv2r1gw0000gn/T/go-build914982300=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Build android library using gomobile (commit a42111704963f4f0d1266674e1e97489aa8dcca0):

GO111MODULE=off ${GOPATH}/bin/gomobile bind -target=android -tags="android" -v -o ./build/Lndmobile.aar github.com/lightningnetwork/lnd/mobile

where the package lndmobile is defined as here: https://github.com/halseth/lnd/tree/mobile-support/mobile

This creates a library Lndmobile.aar which I import into an Android Studio project: https://github.com/lightninglabs/lightning-app/blob/expokit-32/mobile/android/app/src/main/java/host/exp/exponent/LndNativeModule.java

What did you expect to see?

App builds and runs, both in debug and release modes.

What did you see instead?

App works in debug mode, but in release mode (Build->Generate Signed APK) it crashes with error

02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148] No pending exception expected: java.lang.ClassNotFoundException: Didn't find class "lndmobile.Lndmobile$proxyCallback" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.google.android.apps.mtaas.crawler-8_-i2i64DrNb9s4Hpvcoqg==/base.apk", zip file "/data/app/engineering.lightning.LightningApp-YDmR4u0ypHHFvfyOS8qZGw==/base.apk"],nativeLibraryDirectories=[/data/app/com.google.android.apps.mtaas.crawler-8_-i2i64DrNb9s4Hpvcoqg==/lib/arm64, /data/app/engineering.lightning.LightningApp-YDmR4u0ypHHFvfyOS8qZGw==/lib/arm, /data/app/com.google.android.apps.mtaas.crawler-8_-i2i64DrNb9s4Hpvcoqg==/base.apk!/lib/armeabi-v7a, /data/app/engineering.lightning.LightningApp-YDmR4u0ypHHFvfyOS8qZGw==/base.apk!/lib/armeabi-v7a, /system/lib]]
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:134)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at void lndmobile.Lndmobile._init() (Lndmobile.java:-2)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at void lndmobile.Lndmobile.<clinit>() (Lndmobile.java:12)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at void lndmobile.Lndmobile.start(java.lang.String, lndmobile.Callback) (Lndmobile.java:-2)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at void host.exp.exponent.LndNativeModule$1.run() (LndNativeModule.java:155)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148]   at void java.lang.Thread.run() (Thread.java:764)
02-14 03:51:26.714: A/ng.LightningAp(11522): thread.cc:2148] 

Inspecting the generated APKs shows that lndmobile.Lndmobile$proxyCallback gets stripped from the release APK. The following patch seems to resolve it, by adding the package name to the proguard rules:

diff --git a/cmd/gomobile/bind_androidapp.go b/cmd/gomobile/bind_androidapp.go
index 9897fbd..6d2ebfa 100644
--- a/cmd/gomobile/bind_androidapp.go
+++ b/cmd/gomobile/bind_androidapp.go
@@ -160,6 +160,7 @@ func buildAAR(srcDir, androidDir string, pkgs []*build.Package, androidArchs []s
                return err
        }
        fmt.Fprintln(w, `-keep class go.** { *; }`)
+       fmt.Fprintln(w, `-keep class lndmobile.** { *; }`)

        w, err = aarwcreate("classes.jar")
        if err != nil {

Let me know if this is a desired addition, or if there is a better way to resolve this issue.

@gopherbot gopherbot added this to the Unreleased milestone Feb 15, 2019
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Feb 15, 2019
@bcmills
Copy link
Contributor

bcmills commented Feb 28, 2019

CC @eliasnaur @hyangah

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 28, 2019
@gopherbot
Copy link

Change https://golang.org/cl/164798 mentions this issue: cmd/gomobile: add generated package names to proguard.txt

@eliasnaur
Copy link
Contributor

@halseth please test https://golang.org/cl/164798 as I couldn't figure out how to enable class stripping for our gradle tests.

@halseth
Copy link
Author

halseth commented Mar 5, 2019

Confirming that https://golang.org/cl/164798 fixes my issue! Thanks 👍

@golang golang locked and limited conversation to collaborators Mar 4, 2020
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 10, 2021
No test as I couldn't figure out how to persuade gradle test to
strip classes.

Fixes golang/go#30251

Change-Id: I7dca9169a4a8eb31b981ad49047a6bdfa6f6efd7
Reviewed-on: https://go-review.googlesource.com/c/164798
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
imWildCat pushed a commit to imWildCat/go-mobile that referenced this issue Apr 11, 2021
No test as I couldn't figure out how to persuade gradle test to
strip classes.

Fixes golang/go#30251

Change-Id: I7dca9169a4a8eb31b981ad49047a6bdfa6f6efd7
Reviewed-on: https://go-review.googlesource.com/c/164798
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
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 NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants