繁体   English   中英

无法使用Maven在Android Studio中导入GSON / JSON

[英]Cannot Import GSON/JSON in Android Studio Using Maven

我在使用Maven导入com.google.gson时遇到问题。 目前,我收到以下错误:

Error:(24, 17) Failed to resolve: junit:junit:4.12

Error:(22, 13) Failed to resolve: com.google.code.gson:gson:2.5

这是该项目的build.gradle:

buildscript {
    repositories {
        jcenter()
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

repositories {
    jcenter()
    mavenCentral()
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是“模块:应用程序”的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.name.testversion"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.google.code.gson:gson:2.5'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
}

请告诉我该如何解决这些问题,并将“ com.google.code.gson:gson:2.5”成功导入到Android Studio中以与此项目一起使用。

另外,您应该知道,我是刚接触Android Studio的人,这只是我的观点,这是我第一次在Android Studio中使用Maven,但通常不是第一次使用Maven。

在您的Project build.grade尝试使用:

allprojects {

    repositories {
        jcenter()
        mavenCentral()
    }
}

不仅仅是repositories {...}

将您的项目gradle更改为此

//顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

buildscript {
    repositories {
        jcenter()
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM