Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

android - Adding local .aar files to my gradle build

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...