如何在build.gradle中包含多个存储库?

时间:2015-01-23 01:03:02

标签: android maven gradle android-gradle

Android Studio不会让我构建它。它说没有找到com.mixpanel.blahblahblah。 com.mixpanel.blahblahblah来自mavenCentral() 我知道问题是因为它无法识别mavenCentral(),因为它只识别其他repo。我怎样才能包含这两个项目并让这个项目有效?

apply plugin: 'com.android.application'
apply plugin: 'crashlytics'

buildscript {
    repositories {
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
    }
}


repositories {
    maven { url 'http://download.crashlytics.com/maven' }
    mavenCentral()
}


android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "co.dilmile.dilmile"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.parse.bolts:bolts-android:1.1.2'
    compile 'com.loopj.android:android-async-http:1.4.6'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.facebook.android:facebook-android-sdk:3.20.0'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'org.roboguice:roboguice:3.+'
    compile 'com.google.code.findbugs:jsr305:1.3.9'
    provided 'org.roboguice:roboblender:3.+'
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.mixpanel.android:mixpanel-android:4.5.3'
}

4 个答案:

答案 0 :(得分:7)

我认为您应该将maven central添加到您的buildscript存储库中。我喜欢这样,没问题:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }
...
}

allprojects {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }
}

编辑:我相信你的gradle文件应该是

apply plugin: 'com.android.application'
apply plugin: 'crashlytics'

buildscript {
    repositories {
        maven { url 'http://download.crashlytics.com/maven' }
        mavenCentral()
    }

    dependencies {
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
    }
}


repositories {
    maven { url 'http://download.crashlytics.com/maven' }
    mavenCentral()
}


android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "co.dilmile.dilmile"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.parse.bolts:bolts-android:1.1.2'
    compile 'com.loopj.android:android-async-http:1.4.6'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.facebook.android:facebook-android-sdk:3.20.0'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'org.roboguice:roboguice:3.+'
    compile 'com.google.code.findbugs:jsr305:1.3.9'
    provided 'org.roboguice:roboblender:3.+'
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.mixpanel.android:mixpanel-android:4.5.3'
}

答案 1 :(得分:1)

由于现在Android Studio使用jcenter而不是maven,您应该通过将mavenCentral更改为jcenter来迁移存储库

buildscript {
    repositories {
        //old
        //mavenCentral()
        //new
        jcenter()
        maven { url 'http://download.crashlytics.com/maven' }
    }
...
}

allprojects {
    repositories {
        //old
        //mavenCentral()
        //new
        jcenter()
        maven { url 'http://download.crashlytics.com/maven' }
    }
}

jcenter比mavenCentral更完整,更快

答案 2 :(得分:0)

jcenter将镜像mavenCentral存储库,以便在遇到mavenCentral问题时可以使用jcenter。

并尝试避免在声明版本号的依赖项中使用+。 它也可能是个问题。

我最近编写了一个依赖管理工具来找出哪些依赖项已经过时,你可以尝试一下。

https://github.com/Jintin/andle

答案 3 :(得分:0)

使用此

console.log(globalString); // Output: "This can be accessed anywhere!"

globalString = "Check me out now";
console.log(globalString); // Output: "Check me out now"

globalString = undefined;
console.log(globalString); // Output: undefined```