このgradleビルドスクリプトを使用したAndroidライブラリプロジェクトがあります:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group 'com.test'
version '0.0.1'
android {
compileSdkVersion 19
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.test.sdk"
minSdkVersion 14
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile 'com.android.support:support-v4:21.0.2'
compile 'com.google.code.gson:gson:2.3'
}
次に、このビルド スクリプトを使用してアプリケーションを作成します。
プラグインを適用: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.test.app"
minSdkVersion 14
targetSdkVersion 19
multiDexEnabled true
}
signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile ('com.test:sdk:0.0.1@aar') {
transitive = true
}
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:support-v4:21.0.2'
compile 'com.google.android.gms:play-services:6.1.71'
}
Maven プラグインを使用して、ライブラリ SDK をローカルの Maven リポジトリに公開しています: https://github.com/dcendents/android-maven-plugin
ライブラリ プロジェクトでインストール タスクを実行すると、pom ファイルと共にライブラリ .aar が正常に公開されます。pom ファイルには、コンパイルの依存関係として gson がリストされています。
生成された POM ファイル:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>sdk</artifactId>
<version>0.0.1</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
アプリケーションを実行すると、gson クラスに対して java.lang.NoClassDefFoundError が発生します。apk を見ると、gson dep がまったく取り込まれていないことがわかります。
依存関係に拡張子 '@aar' を配置すると、遷移が false に設定され、遷移の依存関係がプルされないことを読みました。そこで、transitive = true を追加しました。「@aar」拡張子なしでも試してみましたが、同じ問題に遭遇しました。
Android Studio RC1 with gradle plugin version 0.14.4 を使用しています。