Gradle indentation issue in Android Studio 2.3

孤街醉人 提交于 2019-12-23 09:33:48

问题


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?


回答1:


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'
...



回答2:


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.



来源:https://stackoverflow.com/questions/42984981/gradle-indentation-issue-in-android-studio-2-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!