Android golang绑定刷新*.aar

huangapple go评论92阅读模式
英文:

Android golang bind refresh *.aar

问题

我正在使用新模块导入一个aar文件,选择"import JAR or AAR package"选项。最初,我能够从我的库中调用一个方法。然而,在更新库并再次运行Gomobile bind之后,我无法弄清楚如何更新aar文件。在手动更新.aar文件后,新的方法没有显示出来。
重新导入会导致"Project already contains subproject with name mobilelib"的错误。

Android Studio 2.2.3
如何刷新.aar文件?

build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "com.testing.testgolanglib"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    compile project(':mobilelib')
}

mobilelib

configurations.maybeCreate("default")
artifacts.add("default", file('mobilelib.aar'))

Project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        flatDir{
            dirs '/Users/abc/projects/go/src/com.abc/mobilelib'
        }

    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}
英文:

I am importing an aar file using the new module > import JAR or AAR package option. Initially I was able call a method from my library. However after updating the library and running Gomobile bind again, I can't figure out how to update the aar file. The new methods are not shown after updating the .aar file manually.
Importing again causes "Project already contains subproject with name mobilelib".

Android Studio 2.2.3
How do I refresh the .aar file?

build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "com.testing.testgolanglib"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    compile project(':mobilelib')
}

mobilelib

configurations.maybeCreate("default")
artifacts.add("default", file('mobilelib.aar'))

Project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        flatDir{
            dirs '/Users/abc/projects/go/src/com.abc/mobilelib'
        }

    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

答案1

得分: 1

理论上,你有两个选项:

  1. 每次更改库文件时,手动运行gomobile bind命令,然后将AAR文件从Go源代码目录复制到mobilelib目录,替换旧的AAR文件。最后重新构建项目;

  2. 使用org.golang.mobile.bind Gradle插件,该插件应该可以为你完成所有这些工作。

但据我所知,该插件与最新的Gradle工具不兼容,并且无法正常工作。

英文:

In theory, you have two options:

  1. Run gomobile bind manually each time you change the library, then copy the AAR file from your Go source directory to the mobilelib directory, replacing the old AAR file. And, finally rebuild the project;

  2. Use the org.golang.mobile.bind Gradle plugin, that is supposed to do all of this work for you.

But, as far as I know, the plugin is not up-to-date with the latest Gradle tools and doesn't work properly.

答案2

得分: 0

我遇到了同样的问题。我通过在Go语言中简化一个新函数来解决它。我使用了由gomobile数据类型支持的结构体来返回结果,当我简化函数(将结果编码为简单的字符串)时,一切都正常工作了。

英文:

I had the same problem. I solved it by simplifying a new function on golang. I used struct with supported by gomobile data types to return the result, when I simplified the function (encoded the result into a simple string), everything worked.

huangapple
  • 本文由 发表于 2017年2月5日 12:04:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/42048423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定