所以我创建了一个Android-Library,并成功地将其编译成.aar文件,我称之为aar文件:"projectx-sdk-1.0.0.aar"现在我希望我的新项目依赖于这个aar所以我所做的就是关注这篇文章:http:// life. nimbco.us/referencing-local-aar-files-with-android-studios-new-gradle-based-build-system/
但由于我没有得到预期的结果,这篇文章让我感到困惑:
aar的包名是:com.projectx.photosdk并调用里面的模块sdk
这是我目前的项目结构:
|-SuperAwesomeApp
|--.idea
|--gradle
|--App
|---aars
|----projectx-sdk-1.0.0.aar
|---build
|---jars
|---src
|---build.gradle
Run Code Online (Sandbox Code Playgroud)
他是我的gradle构建文件:
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.projectx.photosdk:sdk:1.0.0@aar'
// compile files( …Run Code Online (Sandbox Code Playgroud) 我已经看到各种开发者发布的问题(Android Studio将两个.aar合并为一个和其他),但我没有看到一个明确的响应,使我能够创建一个包含一个或多个AAR或JAR的AAR(我可以使用JAR因为我不需要共享任何资源;只有类).这是我的库项目的app.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.1'
compile ('libs/eventbus.jar')
compile project(':core-release')
compile project(':midware-release')
}
Run Code Online (Sandbox Code Playgroud)
同样,这个应用程序是一个库项目,需要两个其他库项目('核心发布','midware-release'),虽然我能够生成一个我可以在我的应用程序中使用的AAR文件,但应用程序无法找到依赖库项目的类,我必须将两个库项目的AAR添加到我的应用程序中.
这是app.gradle应用程序项目(无需手动添加JAR),无法找到依赖项目的类:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.app.sample"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies …Run Code Online (Sandbox Code Playgroud) 我正在实现一个具有推送通知和api的库项目.在这个库中,我使用了一些外部库,如playservice-gcm,gson,retrofit等.如果我用库项目编译示例,那么一切都很好.但是当我使用aar文件时,示例项目无法找到我使用的外部库.
下面是我的库的builde.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.android.support:appcompat-v7:22.2.0')
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.jakewharton:butterknife:5.0.0'
compile 'com.squareup.retrofit:retrofit:1.7.1'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile files('libs/commons-io-2.4.jar')
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
}
Run Code Online (Sandbox Code Playgroud)
以下就是一个例子
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// compile project(':library') => this is the the libs having …Run Code Online (Sandbox Code Playgroud)