所以,我创建了一个Android的图书馆和成功地编译成一个.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
| - 思路
| --gradle
| --App
| --- AARS
| ---- ProjectX的-SDK-1.0.0.aar
| ---构建
| ---罐子
| --- SRC
| --- build.gradle
和他是我的摇篮构建文件:
应用插件:'机器人'
buildscript {
库{
mavenCentral()
flatDir {
迪尔斯AARS
}
}
}
安卓{
compileSdkVersion 19
buildToolsVersion19.0.1
defaultConfig {
的minSdkVersion 11
targetSdkVersion 19
版本code 1
VERSIONNAME1.0
}
buildTypes {
推出 {
runProguard假
proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'ProGuard的-rules.txt
}
}
}
依赖{
编译com.android.support:gridlayout-v7:19.0.1
编译com.android.support:support-v4:19.0.1
编译com.android.support:appcompat-v7:19.0.1
编译com.projectx.photosdk:SDK:1.0.0@aar
//编译文件(AARS / SDK-1.0.0.aar)//也不起作用
}
//修改
我收到错误的:
无法刷新摇篮工程SuperAwesomeApp
找不到com.projectx.photosdk:SDK:1.0.0。
要求:
SuperAwesomeApp:应用程序:不详
解决方案
近年来,随着Android的Studio版本,与1.3测试,使用本地.AAR文件,而不是一个来自行家/ jcenter仓库提取,刚去的文件>新建>新建模块并选择导入.JAR / .AAR包装
您将最终得到的是项目中的一个新的模块,它包含非常简单的 build.gradle 文件看起来或多或少是这样的:
configurations.create(默认)
artifacts.add(默认,文件(这 - 是 - 你 - 封装 - 在-AAR-format.aar'))
当然,其他项目要引用这个新的模块与普通的编制项目指令。因此,在使用这个新的模块,这是简单的一个项目,一个本地.aar文件中有这样它的 build.gradle
[...]
依赖{
编译文件树(导演:库,包括:['的* .jar'])
testCompile'的JUnit:JUnit的:4.12
ompilecom.android.support:appcompat-v7:23.1.0
编译com.android.support:design:23.1.0
[...]
编制项目(:名称模块创建-通的新模块选项描述的,上面的')
}
[...]
So i have created a Android-Library and succesfully compiled it into a .aar file i called this aar file: "projectx-sdk-1.0.0.aar"
now i want my new project to depend on this aar so what i have did is follow this post: http://life.nimbco.us/referencing-local-aar-files-with-android-studios-new-gradle-based-build-system/
But the post confuses me since i do not get the desired result:
The package name of the aar is : com.projectx.photosdk
and the module inside is called sdk
here is my current project structure:
|-SuperAwesomeApp
|--.idea
|--gradle
|--App
|---aars
|----projectx-sdk-1.0.0.aar
|---build
|---jars
|---src
|---build.gradle
And he is my gradle build file:
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( 'aars/sdk-1.0.0.aar' ) // Does not work either
}
// EDIT
The errors i am getting:
Failed to refresh Gradle project 'SuperAwesomeApp'
Could not find com.projectx.photosdk:sdk:1.0.0.
Required by:
SuperAwesomeApp:App:unspecified
解决方案
With recent versions of Android Studio, tested with 1.3, to use local .AAR file and not one fetched from maven/jcenter repository, just go to File > New > New module and choose Import .JAR/.AAR Package.
What you will end up with is a new module in your project that contains very simple build.gradle file that looks more or less like this:
configurations.create("default")
artifacts.add("default", file('this-is-yours-package-in-aar-format.aar'))
Of course, other projects have to reference this new module with regular compile project directive. So in a project that uses this new module which is simple a local .aar file has this in it's build.gradle
[...]
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
ompile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
[...]
compile project(':name-of-module-created-via-new-module-option-described-above')
}
[...]
相关推荐
最新文章