将本地 .aar 文件添加到我的 gradle 构建中 [英] Adding local .aar files to my gradle build
问题描述
所以我创建了一个 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/
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:
aar的包名是:com.projectx.photosdk
,里面的模块叫做sdk
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
他是我的 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
}
//编辑
我遇到的错误:
Failed to refresh Gradle project 'SuperAwesomeApp'
Could not find com.projectx.photosdk:sdk:1.0.0.
Required by:
SuperAwesomeApp:App:unspecified
推荐答案
您将 flatDir
块放在错误的 repostories
块中.buildscript
中的 repositories
块告诉 Gradle 在哪里可以找到 Android-Gradle 插件,而不是其余的依赖项.您需要有另一个像这样的顶级 repositories
块:
You put your flatDir
block in the wrong repostories
block. The repositories
block inside buildscript
tells Gradle where to find the Android-Gradle plugin, but not the rest of the dependencies. You need to have another top-level repositories
block like this:
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
我对此进行了测试,它在我的设置上运行正常.
I tested this and it works okay on my setup.
这篇关于将本地 .aar 文件添加到我的 gradle 构建中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!