android - Gradle错误:JSON标准不允许此类 token (android studio 3.0)

标签 android gradle

我有这个问题和相对的解决方案,但我不知道为什么

我刚刚升级到Android 3.0,并尝试编译我的应用程序。如果我有这个结构,我在gradle.build中会有很多错误(我会保留相关部分)

android{
    ....
 }
dependencies {
  ....
 }

并且错误是 JSON标准不允许这种 token

但是如果我将结构更改为
android {
    ....

    dependencies {
     ....
     }
 }

(依赖是INSIDE android对象)

错误出现在这里:
compile '**com.android.support**:support-v4:26.1.0'
compile '**com.loopj.android**:android-async-http:1.4.9'

另一个错误提示“期望,得到':'”
有任何想法吗 ?

最佳答案

是的,情况已经改变。如下做

这是最好的方法。

在您的根级别gradle.build中使用以下

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
}

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

并在gradle-wrapper.properties文件中更改包装器版本,如下所示
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

同样在您的应用程序级别build.gradle中,确保您使用的是以下26种版本
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.xxxx"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    debugCompile project(':debug-db')
    compile project(':tracker')
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.google.android.gms:play-services-location:11.4.2'
    compile 'com.google.android.gms:play-services-places:11.4.2'
    compile 'com.google.android.gms:play-services-maps:11.4.2'


    compile 'com.google.firebase:firebase-core:11.4.2'
    compile 'com.google.firebase:firebase-crash:11.4.2'
    compile 'com.google.firebase:firebase-messaging:11.4.2'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.7'
    compile 'com.github.safetysystemtechnology:location-tracker-background:v1.2'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    testCompile 'junit:junit:4.12'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

关于android - Gradle错误:JSON标准不允许此类 token (android studio 3.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46951961/

相关文章:

android - MPAndroid Chart如何制作流畅的折线图

android - Android 上蓝牙扫描和发现的差异

android - Android Gradle 配置中 API 的 buildTypes.each 字符串

android - Android 项目中缺少 Gradle 构建任务 installRelease

java - 以字符串形式将联系人作为 vCard 启动 Intent

gradle - Grails 3.3.10中的org.codehaus.groovy.runtime.DefaultGroovyMethods错误

gradle - Gradle:解决依赖项 “Could not parse POM”

android - 使用 Gradle Kotlin DSL 在 settings.gradle.kts 中设置 gradle.ext

android - 在启用测试模式后,Gradle构建失败?

Android - 位置不更新