Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist Open File
34,415
Solution 1
In your top-level file use:
ext {
compileSdkVersion = 26
}
In your module/build.gradle
file use:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
...
}
Solution 2
Another way:
Your build.gradle
in top-level module
ext {
minSdk = 21
targetSdk = 29
compileSdk = 29
buildTools = '29.0.3'
}
Your build.gradle
in app module
android {
def buildConfig = rootProject.extensions.getByName("ext")
compileSdkVersion buildConfig.compileSdk
buildToolsVersion buildConfig.buildTools
defaultConfig {
minSdkVersion buildConfig.minSdk
targetSdkVersion buildConfig.targetSdk
}
// ...
}
Related videos on Youtube
Author by
vittochan
Updated on June 21, 2020Comments
-
vittochan about 4 years
I imported a project downloaded from GitHub into my Android Studio project as module. The "Import module..." wizard worked fine, but when the Adroid Studio tried to rebuild the project, it returned me this error:
Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist Open File
The error is related to this line in the "build.gradle" file of the imported module:
compileSdkVersion rootProject.compileSdkVersion
I tried to add "ext" section in the project "build.gradle" like this:
ext { compileSdkVersion 26 }
But in this way I receive a new error:
Gradle DSL method not found: 'compileSdkVersion()' Possible causes: ...
-
DeKaNszn over 6 yearsAdd your build.gradle
-
-
vittochan over 6 yearsIf I add the block "ext { compileSdkVersion = 26 }" in the top-level (build.gradle), the build action return me this error: Error:(26, 1) A problem occurred evaluating root project 'mySticker'. > Could not find method compileSdkVersion() for arguments [26] on object of type org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension.
-
Gabriele Mariotti over 6 yearsAre you sure about the = sign? Because this error happens if you add compileSdkVersion 26 without sign
-
jeancode almost 6 yearsWhat is the 'top level file'?
-
Gabriele Mariotti almost 6 years@jeancode the build.gradle in the root of the project
-
Isaac almost 6 years@GabrieleMariotti: Thanks that it solved for properties
compileSdkVersion
but it gives the same error but on another propertybuildToolsVersion
. I assume that I can apply same way for this property too? -
Gabriele Mariotti almost 6 years@Isaac Yes you can.
-
Michael Z almost 6 yearsFor those who not on Android: it is needed to set project.ext but not just ext
-
stackunderflow over 5 yearssorry i cannot find "top-level" file. is there any other name it has?. mind telling us here?
-
Gabriele Mariotti over 5 years@jerinho The top level file is the build.gradle that you can find in the root of the project.
-
fun joker over 5 years@GabrieleMariotti Can you please help me here: stackoverflow.com/questions/53440756/…
-
fun joker over 5 years@GabrieleMariotti I followed all your steps mentioned in the answer. So I have made changes in
android -> app->build.gradle file
andandroid-> build.gradle
file is it correct ? -
fun joker over 5 years@Isaac it solved for properties compileSdkVersion but it gives the same error for another property buildToolsVersion after build tools it says minSdkVersion why am I getting all this ? Can you please help me here: stackoverflow.com/questions/53440756/…
-
Aabir Hussain about 5 yearsit will be better for freshers like me if you give an example for rootProject and top-level in your answer. Thanks BTW it works for me
-
Daniel about 5 yearsI also get this
Could not find method compileSdkVersion() for arguments
, no matter what I do. Now I hardcoded the version everywhere. Can somebody give an example with whole file contents, please?!