4

We are facing a compilation issue when we try to compile an AAR version of our framework with gomobile bind. It's binding fine with the iOS Framework.

Here is the error we get:

$ make build_android

cd ./gomobile/logger && gomobile bind -o ../build/logger.aar -target=android . ../levelenum ../remotelogger ../apiclient ../userproperties

gomobile: javac -d /var/folders/p6/vvxrsdbj1bg87kkgk3k77cn40000gp/T/gomobile-work-357624003/javac-output -source 1.7 -target 1.7 -bootclasspath /Users/robin/Library/Android/sdk/platforms/android-29/android.jar apiclient/Apiclient.java apiclient/AuthenticationArgs.java apiclient/PostArgs.java go/Seq.java go/Universe.java go/error.java levelenum/Level.java levelenum/Levelenum.java logger/Logger.java logger/Logger_.java remotelogger/Remotelogger.java userproperties/ApplicationProperties.java userproperties/CarrierProperties.java userproperties/DeviceProperties.java userproperties/NetworkProperties.java userproperties/OSProperties.java userproperties/Userproperties.java failed: exit status 1
apiclient/Apiclient.java:12: error: class APIClient is public, should be declared in a file named APIClient.java
public final class APIClient implements Seq.Proxy {
             ^
remotelogger/Remotelogger.java:12: error: class RemoteLogger is public, should be declared in a file named RemoteLogger.java
public final class RemoteLogger implements Seq.Proxy {
             ^
userproperties/Userproperties.java:12: error: class UserProperties is public, should be declared in a file named UserProperties.java
public final class UserProperties implements Seq.Proxy {
             ^
./apiclient/Apiclient.java:12: error: class APIClient is public, should be declared in a file named APIClient.java
public final class APIClient implements Seq.Proxy {
             ^
apiclient/Apiclient.java:13: error: cannot access Apiclient
        static { Apiclient.touch(); }
                 ^
  bad source file: ./apiclient/Apiclient.java
    file does not contain class apiclient.Apiclient
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.
5 errors

make: *** [build_android] Error 1

For instance our APIClient.go file looks like this:

package apiclient

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "time"
)

// APIClient : handler of the Network request
type APIClient struct {
    BaseURL string
}

And the folder structure is:

gomobile/
    Makefile
    go.mod
    go.sum
    build/
        logger.framework (iOS)
        logger.aar (Android) <---- Should be here but cannot be built
    apiclient/
        apiclient.go
    logger/
        logger.go
    userproperties/
        userproperties.go
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Nicolas Charvoz
  • 1,509
  • 15
  • 41

1 Answers1

0

Although this question is pretty old, I just ran into the same problem and thought I could post the solution here in case others ran into this issue.

It seems the problem is due to the type having the same name as the package. Renaming one of them resolved the issue for me.

DRK3
  • 1
  • 1