Android 用ライブラリ公開手順
Android 用ライブラリ公開手順
プロジェクト
- 環境
- Android Studio 2.0
サンプルプロジェクト作成
ひとまず普通に新規プロジェクト作成にて適当にアプリプロジェクトを作る。
このプロジェクトにライブラリをモジュールとして追加していく。
アプリプロジェクトはライブラリの組み込みサンプルとして使用できる。
ライブラリモジュールの追加
プロジェクトを右クリックし、New -> Module を選択。
Android Library を選んで Next 押下。
名前と Minimum SDK を設定する。
ライブラリモジュール内のサンプル実装
適当にクラスを作成し、ログを吐くだけのメソッドを定義してみる。
package com.example.librarytest; import android.util.Log; /** * Created by furuekazuhiro on 2016/04/18. */ public class SampleLibrary { public void sampleMethod() { Log.d("test", "test"); } }
サンプルアプリ側でライブラリのメソッドを実行する処理を追加
app の build.gradle に以下を追加。
dependencies { ・ ・ ・ compile project(path: ':librarytest') }
librarytest
の部分にはライブラリモジュールの追加時に設定した名称を記載する。
・ ・ ・ import com.example.librarytest.SampleLibrary; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { ・ ・ ・ new SampleLibrary().sampleMethod(); } }
これでサンプルアプリを実行すればログ出力される(ライブラリのメソッドが実行できていることを確認できる。)
公開用サービスへの登録
ライブラリのビルド
[Android]ライブラリプロジェクト(aar)をMavenリポジトリとしてGitHubで配布する | DevAchieve を参考にさせていただいた。
Android Studio の Terminal で以下を実行。
$ ./gradlew assembleRelease Downloading https://services.gradle.org/distributions/gradle-2.10-all.zip ............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. Unzipping /Users/furuekazuhiro/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst/gradle-2.10-all.zip to /Users/furuekazuhiro/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst Set executable permissions for: /Users/furuekazuhiro/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst/gradle-2.10/bin/gradle Download https://jcenter.bintray.com/com/android/tools/build/gradle/2.0.0/gradle-2.0.0.pom Download https://jcenter.bintray.com/com/android/tools/build/gradle-core/2.0.0/gradle-core-2.0.0.pom Download https://jcenter.bintray.com/com/android/tools/build/builder/2.0.0/builder-2.0.0.pom Download https://jcenter.bintray.com/com/android/tools/lint/lint/25.0.0/lint-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-api.pom Download https://jcenter.bintray.com/com/android/tools/build/gradle-api/2.0.0/gradle-api-2.0.0.pom Download https://jcenter.bintray.com/com/android/databinding/compilerCommon/2.0.0/compilerCommon-2.0.0.pom Download https://jcenter.bintray.com/org/ow2/asm/asm/5.0.3/asm-5.0.3.pom Download https://jcenter.bintray.com/org/ow2/asm/asm-parent/5.0.3/asm-parent-5.0.3.pom Download https://jcenter.bintray.com/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.pom Download https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/5.2.1/proguard-gradle-5.2.1.pom Download https://jcenter.bintray.com/net/sf/proguard/proguard-parent/5.2.1/proguard-parent-5.2.1.pom Download https://jcenter.bintray.com/org/jacoco/org.jacoco.core/0.7.4.201502262128/org.jacoco.core-0.7.4.201502262128.pom Download https://jcenter.bintray.com/org/jacoco/org.jacoco.build/0.7.4.201502262128/org.jacoco.build-0.7.4.201502262128.pom Download https://jcenter.bintray.com/org/antlr/antlr/3.5.2/antlr-3.5.2.pom Download https://jcenter.bintray.com/org/antlr/antlr-master/3.5.2/antlr-master-3.5.2.pom Download https://jcenter.bintray.com/org/sonatype/oss/oss-parent/9/oss-parent-9.pom Download https://jcenter.bintray.com/com/android/tools/build/builder-model/2.0.0/builder-model-2.0.0.pom Download https://jcenter.bintray.com/com/android/tools/build/builder-test-api/2.0.0/builder-test-api-2.0.0.pom Download https://jcenter.bintray.com/com/android/tools/sdklib/25.0.0/sdklib-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/sdk-common/25.0.0/sdk-common-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/common/25.0.0/common-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/build/manifest-merger/25.0.0/manifest-merger-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/ddms/ddmlib/25.0.0/ddmlib-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/jack/jack-api/0.9.0/jack-api-0.9.0.pom Download https://jcenter.bintray.com/com/android/tools/jill/jill-api/0.9.0/jill-api-0.9.0.pom Download https://jcenter.bintray.com/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.pom Download https://jcenter.bintray.com/com/android/tools/lint/lint-checks/25.0.0/lint-checks-25.0.0.pom Download https://jcenter.bintray.com/org/eclipse/jdt/core/compiler/ecj/4.4.2/ecj-4.4.2.pom Download https://jcenter.bintray.com/com/android/tools/annotations/25.0.0/annotations-25.0.0.pom Download https://jcenter.bintray.com/com/google/guava/guava/17.0/guava-17.0.pom Download https://jcenter.bintray.com/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom Download https://jcenter.bintray.com/com/android/databinding/baseLibrary/2.0.0/baseLibrary-2.0.0.pom Download https://jcenter.bintray.com/com/tunnelvisionlabs/antlr4/4.5/antlr4-4.5.pom Download https://jcenter.bintray.com/com/tunnelvisionlabs/antlr4-master/4.5/antlr4-master-4.5.pom Download https://jcenter.bintray.com/commons-io/commons-io/2.4/commons-io-2.4.pom Download https://jcenter.bintray.com/org/apache/commons/commons-parent/25/commons-parent-25.pom Download https://jcenter.bintray.com/org/apache/apache/9/apache-9.pom Download https://jcenter.bintray.com/com/googlecode/juniversalchardet/juniversalchardet/1.0.3/juniversalchardet-1.0.3.pom Download https://jcenter.bintray.com/net/sf/proguard/proguard-base/5.2.1/proguard-base-5.2.1.pom Download https://jcenter.bintray.com/org/ow2/asm/asm-debug-all/5.0.1/asm-debug-all-5.0.1.pom Download https://jcenter.bintray.com/org/ow2/asm/asm-parent/5.0.1/asm-parent-5.0.1.pom Download https://jcenter.bintray.com/org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2.pom Download https://jcenter.bintray.com/org/antlr/ST4/4.0.8/ST4-4.0.8.pom Download https://jcenter.bintray.com/com/android/tools/layoutlib/layoutlib-api/25.0.0/layoutlib-api-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/dvlib/25.0.0/dvlib-25.0.0.pom Download https://jcenter.bintray.com/com/android/tools/repository/25.0.0/repository-25.0.0.pom Download https://jcenter.bintray.com/com/google/code/gson/gson/2.2.4/gson-2.2.4.pom Download https://jcenter.bintray.com/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.pom Download https://jcenter.bintray.com/org/apache/commons/commons-parent/33/commons-parent-33.pom Download https://jcenter.bintray.com/org/apache/apache/13/apache-13.pom Download https://jcenter.bintray.com/com/android/tools/lint/lint-api/25.0.0/lint-api-25.0.0.pom Download https://jcenter.bintray.com/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.pom Download https://jcenter.bintray.com/com/tunnelvisionlabs/antlr4-runtime/4.5/antlr4-runtime-4.5.pom Download https://jcenter.bintray.com/com/tunnelvisionlabs/antlr4-annotations/4.5/antlr4-annotations-4.5.pom Download https://jcenter.bintray.com/com/intellij/annotations/12.0/annotations-12.0.pom Download https://jcenter.bintray.com/com/android/tools/external/lombok/lombok-ast/0.2.3/lombok-ast-0.2.3.pom Download https://jcenter.bintray.com/org/abego/treelayout/org.abego.treelayout.core/1.0.1/org.abego.treelayout.core-1.0.1.pom Download https://jcenter.bintray.com/com/android/tools/build/gradle/2.0.0/gradle-2.0.0.jar Download https://jcenter.bintray.com/com/android/tools/build/gradle-core/2.0.0/gradle-core-2.0.0.jar Download https://jcenter.bintray.com/com/android/tools/build/builder/2.0.0/builder-2.0.0.jar Download https://jcenter.bintray.com/com/android/tools/lint/lint/25.0.0/lint-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-api.jar Download https://jcenter.bintray.com/com/android/tools/build/gradle-api/2.0.0/gradle-api-2.0.0.jar Download https://jcenter.bintray.com/com/android/databinding/compilerCommon/2.0.0/compilerCommon-2.0.0.jar Download https://jcenter.bintray.com/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar Download https://jcenter.bintray.com/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.jar Download https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/5.2.1/proguard-gradle-5.2.1.jar Download https://jcenter.bintray.com/org/jacoco/org.jacoco.core/0.7.4.201502262128/org.jacoco.core-0.7.4.201502262128.jar Download https://jcenter.bintray.com/org/antlr/antlr/3.5.2/antlr-3.5.2.jar Download https://jcenter.bintray.com/com/android/tools/build/builder-model/2.0.0/builder-model-2.0.0.jar Download https://jcenter.bintray.com/com/android/tools/build/builder-test-api/2.0.0/builder-test-api-2.0.0.jar Download https://jcenter.bintray.com/com/android/tools/sdklib/25.0.0/sdklib-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/sdk-common/25.0.0/sdk-common-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/common/25.0.0/common-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/build/manifest-merger/25.0.0/manifest-merger-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/ddms/ddmlib/25.0.0/ddmlib-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/jack/jack-api/0.9.0/jack-api-0.9.0.jar Download https://jcenter.bintray.com/com/android/tools/jill/jill-api/0.9.0/jill-api-0.9.0.jar Download https://jcenter.bintray.com/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar Download https://jcenter.bintray.com/com/android/tools/lint/lint-checks/25.0.0/lint-checks-25.0.0.jar Download https://jcenter.bintray.com/org/eclipse/jdt/core/compiler/ecj/4.4.2/ecj-4.4.2.jar Download https://jcenter.bintray.com/com/android/tools/annotations/25.0.0/annotations-25.0.0.jar Download https://jcenter.bintray.com/com/google/guava/guava/17.0/guava-17.0.jar Download https://jcenter.bintray.com/com/android/databinding/baseLibrary/2.0.0/baseLibrary-2.0.0.jar Download https://jcenter.bintray.com/com/tunnelvisionlabs/antlr4/4.5/antlr4-4.5.jar Download https://jcenter.bintray.com/commons-io/commons-io/2.4/commons-io-2.4.jar Download https://jcenter.bintray.com/com/googlecode/juniversalchardet/juniversalchardet/1.0.3/juniversalchardet-1.0.3.jar Download https://jcenter.bintray.com/net/sf/proguard/proguard-base/5.2.1/proguard-base-5.2.1.jar Download https://jcenter.bintray.com/org/ow2/asm/asm-debug-all/5.0.1/asm-debug-all-5.0.1.jar Download https://jcenter.bintray.com/org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2.jar Download https://jcenter.bintray.com/org/antlr/ST4/4.0.8/ST4-4.0.8.jar Download https://jcenter.bintray.com/com/android/tools/layoutlib/layoutlib-api/25.0.0/layoutlib-api-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/dvlib/25.0.0/dvlib-25.0.0.jar Download https://jcenter.bintray.com/com/android/tools/repository/25.0.0/repository-25.0.0.jar Download https://jcenter.bintray.com/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar Download https://jcenter.bintray.com/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar Download https://jcenter.bintray.com/com/android/tools/lint/lint-api/25.0.0/lint-api-25.0.0.jar Download https://jcenter.bintray.com/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.jar Download https://jcenter.bintray.com/com/tunnelvisionlabs/antlr4-runtime/4.5/antlr4-runtime-4.5.jar Download https://jcenter.bintray.com/com/tunnelvisionlabs/antlr4-annotations/4.5/antlr4-annotations-4.5.jar Download https://jcenter.bintray.com/com/intellij/annotations/12.0/annotations-12.0.jar Download https://jcenter.bintray.com/com/android/tools/external/lombok/lombok-ast/0.2.3/lombok-ast-0.2.3.jar Download https://jcenter.bintray.com/org/abego/treelayout/org.abego.treelayout.core/1.0.1/org.abego.treelayout.core-1.0.1.jar Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preReleaseBuild UP-TO-DATE :app:checkReleaseManifest :app:preDebugBuild UP-TO-DATE :librarytest:preBuild UP-TO-DATE :librarytest:preReleaseBuild UP-TO-DATE :librarytest:compileReleaseNdk UP-TO-DATE :librarytest:compileLint :librarytest:copyReleaseLint UP-TO-DATE :librarytest:checkReleaseManifest :librarytest:preDebugAndroidTestBuild UP-TO-DATE :librarytest:preDebugBuild UP-TO-DATE :librarytest:preDebugUnitTestBuild UP-TO-DATE :librarytest:preReleaseUnitTestBuild UP-TO-DATE :librarytest:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE :librarytest:prepareComAndroidSupportSupportV42221Library UP-TO-DATE :librarytest:prepareReleaseDependencies :librarytest:compileReleaseAidl UP-TO-DATE :librarytest:compileReleaseRenderscript UP-TO-DATE :librarytest:generateReleaseBuildConfig UP-TO-DATE :librarytest:generateReleaseAssets UP-TO-DATE :librarytest:mergeReleaseAssets UP-TO-DATE :librarytest:generateReleaseResValues UP-TO-DATE :librarytest:generateReleaseResources UP-TO-DATE :librarytest:mergeReleaseResources UP-TO-DATE :librarytest:processReleaseManifest UP-TO-DATE :librarytest:processReleaseResources :librarytest:generateReleaseSources :librarytest:compileReleaseJavaWithJavac UP-TO-DATE :librarytest:extractReleaseAnnotations UP-TO-DATE :librarytest:mergeReleaseProguardFiles UP-TO-DATE :librarytest:packageReleaseRenderscript UP-TO-DATE :librarytest:packageReleaseResources UP-TO-DATE :librarytest:processReleaseJavaRes UP-TO-DATE :librarytest:transformResourcesWithMergeJavaResForRelease UP-TO-DATE :librarytest:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE :librarytest:mergeReleaseJniLibFolders UP-TO-DATE :librarytest:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE :librarytest:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE :librarytest:bundleRelease UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42221Library UP-TO-DATE :app:prepareLibImplementSampleLibrarytestUnspecifiedLibrary UP-TO-DATE :app:prepareReleaseDependencies :app:compileReleaseAidl :app:compileReleaseRenderscript :app:generateReleaseBuildConfig :app:generateReleaseAssets UP-TO-DATE :app:mergeReleaseAssets :app:generateReleaseResValues :app:generateReleaseResources :app:mergeReleaseResources :app:processReleaseManifest :app:processReleaseResources :app:generateReleaseSources :app:compileReleaseJavaWithJavac :app:compileReleaseNdk UP-TO-DATE :app:compileReleaseSources :app:lintVitalRelease :app:prePackageMarkerForRelease :app:transformClassesWithDexForRelease :app:mergeReleaseJniLibFolders :app:transformNative_libsWithMergeJniLibsForRelease :app:processReleaseJavaRes UP-TO-DATE :app:transformResourcesWithMergeJavaResForRelease :app:packageRelease :app:assembleRelease :librarytest:compileReleaseSources UP-TO-DATE :librarytest:assembleRelease UP-TO-DATE BUILD SUCCESSFUL Total time: 2 mins 13.357 secs This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
Gradle Daemon
を使うと早くなるらしい。今度調べよう。
$ find . -name '*.aar' ./librarytest/build/outputs/aar/librarytest-debug.aar ./librarytest/build/outputs/aar/librarytest-release.aar
.aar ファイルが生成できていることが確認できる。
公開設定
ライブラリモジュールの build.gradle に以下を追記。
def repo = new File(rootDir, "repository") apply plugin: 'maven' uploadArchives { repositories { mavenDeployer { repository url: "file://${repo.absolutePath}" pom.version = '1.0.0' pom.groupId = 'com.example.librarytest' pom.artifactId = 'librarytest' } } }
Android Studio の Terminal 内で下記を実行。
$ ./gradlew uploadArchives Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preReleaseBuild UP-TO-DATE :app:checkReleaseManifest :app:preDebugBuild UP-TO-DATE :librarytest:preBuild UP-TO-DATE :librarytest:preReleaseBuild UP-TO-DATE :librarytest:compileReleaseNdk UP-TO-DATE :librarytest:compileLint :librarytest:copyReleaseLint UP-TO-DATE :librarytest:checkReleaseManifest :librarytest:preDebugAndroidTestBuild UP-TO-DATE :librarytest:preDebugBuild UP-TO-DATE :librarytest:preDebugUnitTestBuild UP-TO-DATE :librarytest:preReleaseUnitTestBuild UP-TO-DATE :librarytest:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE :librarytest:prepareComAndroidSupportSupportV42221Library UP-TO-DATE :librarytest:prepareReleaseDependencies :librarytest:compileReleaseAidl UP-TO-DATE :librarytest:compileReleaseRenderscript UP-TO-DATE :librarytest:generateReleaseBuildConfig UP-TO-DATE :librarytest:generateReleaseAssets UP-TO-DATE :librarytest:mergeReleaseAssets UP-TO-DATE :librarytest:generateReleaseResValues UP-TO-DATE :librarytest:generateReleaseResources UP-TO-DATE :librarytest:mergeReleaseResources UP-TO-DATE :librarytest:processReleaseManifest UP-TO-DATE :librarytest:processReleaseResources UP-TO-DATE :librarytest:generateReleaseSources UP-TO-DATE :librarytest:compileReleaseJavaWithJavac UP-TO-DATE :librarytest:extractReleaseAnnotations UP-TO-DATE :librarytest:mergeReleaseProguardFiles UP-TO-DATE :librarytest:packageReleaseRenderscript UP-TO-DATE :librarytest:packageReleaseResources UP-TO-DATE :librarytest:processReleaseJavaRes UP-TO-DATE :librarytest:transformResourcesWithMergeJavaResForRelease UP-TO-DATE :librarytest:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE :librarytest:mergeReleaseJniLibFolders UP-TO-DATE :librarytest:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE :librarytest:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE :librarytest:bundleRelease UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42221Library UP-TO-DATE :app:prepareLibImplementSampleLibrarytestUnspecifiedLibrary UP-TO-DATE :app:prepareReleaseDependencies :app:compileReleaseAidl UP-TO-DATE :app:compileReleaseRenderscript UP-TO-DATE :app:generateReleaseBuildConfig UP-TO-DATE :app:generateReleaseAssets UP-TO-DATE :app:mergeReleaseAssets UP-TO-DATE :app:generateReleaseResValues UP-TO-DATE :app:generateReleaseResources UP-TO-DATE :app:mergeReleaseResources UP-TO-DATE :app:processReleaseManifest UP-TO-DATE :app:processReleaseResources UP-TO-DATE :app:generateReleaseSources UP-TO-DATE :app:compileReleaseJavaWithJavac UP-TO-DATE :app:prePackageMarkerForRelease :app:transformClassesWithDexForRelease UP-TO-DATE :app:compileReleaseNdk UP-TO-DATE :app:mergeReleaseJniLibFolders UP-TO-DATE :app:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE :app:processReleaseJavaRes UP-TO-DATE :app:transformResourcesWithMergeJavaResForRelease UP-TO-DATE :app:packageRelease UP-TO-DATE :app:uploadArchives :librarytest:uploadArchives Could not find metadata com.example.librarytest:librarytest/maven-metadata.xml in remote (file:///Users/furuekazuhiro/work/LibImplementSample/repository) BUILD SUCCESSFUL Total time: 21.799 secs This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
これで以下のように repository ディレクトリができるので GitHub に push する。
./LibImplementSample | | |--com | | | |--example | | | | |--librarytest | | | | | |--librarytest | | | | | | |--1.0.0 | | | | | | | |--librarytest-1.0.0.aar | | | | | | | |--librarytest-1.0.0.aar.md5 | | | | | | | |--librarytest-1.0.0.aar.sha1 | | | | | | | |--librarytest-1.0.0.pom | | | | | | | |--librarytest-1.0.0.pom.md5 | | | | | | | |--librarytest-1.0.0.pom.sha1 | | | | | | |--maven-metadata.xml | | | | | | |--maven-metadata.xml.md5 | | | | | | |--maven-metadata.xml.sha1
Android Studio 2.0 でもほぼ同手順で作成できた。