Gradle indentation issue in Android Studio 2.3

2019-06-19 08:29发布

Every time I create a new Activity in AS 2.3 it messes up the build.gradle indentation that results in errors like this.

Error:Could not get unknown property 'compile' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

I have to redo the indentations every time. Any idea how to fix this permanently?

2条回答
对你真心纯属浪费
2楼-- · 2019-06-19 08:47

Don't use compile as a property and don't change the gradle structure.

compile 'com.android.support:appcompat-v7:22.2.1' compile

 'com.parse:parse-android:1.11.0'

Sometimes Gradle build messes up the code like above, it still happens. Probably related to Java JDK updates.

查看更多
Deceive 欺骗
3楼-- · 2019-06-19 08:50

The problem seems to be caused by the lines which contain curly braces like:

compile('com.github.tony19:logback-android-core:1.1.1-4') {
    exclude group: 'ch.qos.logback.core.net'
}

In order to avoid the bug just put all the lines with curly braces above the "usual" (i.e. compile 'something') lines like this:

compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

compile('com.github.tony19:logback-android-core:1.1.1-4') {
    exclude group: 'ch.qos.logback.core.net'
}
compile('com.github.tony19:logback-android-classic:1.1.1-4') {
    exclude group: 'ch.qos.logback.core.net'
}

compile 'com.bolyartech.forge.android:forge-android:6.1.0'
compile 'com.bolyartech.scram_sasl:scram_sasl:2.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup:otto:1.3.6'
compile 'com.google.code.gson:gson:2.7'
compile 'com.github.franmontiel:PersistentCookieJar:v0.9.3'
compile 'com.google.dagger:dagger:2.9'
...
查看更多
登录 后发表回答