Build.gradle: Access to 'project' exceeds its access rights - android

constants.gradle
project.ext {
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
buildToolsVersion = '28.0.3'
supportLibraryVersion = '28.0.0'
}
build.gradle of the app
apply plugin: 'com.android.application'
apply from: '../constants.gradle'
android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
...
What is wrong here?
Though it works fine for libraries in the same project:
Also everything is fine for the next lines in defaultConfig block
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
Android Studio 3.2, classpath 'com.android.tools.build:gradle:3.2.0', distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Seems it didn't show such warnings with the previous Gradle or Studio

It's just a warning and It should work.
Because when you use project inside android scope, Gradle tries to find the invocation location of project.
You have two options to fix this warning.
Get your constants outside of android scope.
def compileSdkVersion = project.ext.compileSdkVersion
def buildToolsVersion = project.ext.buildToolsVersion
android {
compileSdkVersion compileSdkVersion
buildToolsVersion buildToolsVersion
...
Or update your constants.gradle:
ext {
buildVersions = [
minSdkVersion : 19,
compileSdkVersion : 28,
targetSdkVersion : 28,
buildToolsVersion : '28.0.3',
supportLibraryVersion : '28.0.0',
]
}
and use it in your build.gradle like:
apply plugin: 'com.android.application'
apply from: '../constants.gradle'
android {
compileSdkVersion buildVersions.compileSdkVersion
buildToolsVersion buildVersions.buildToolsVersion
...

The same variables naming (compileSdkVersion compileSdkVersion) was incorrect in my case, here's an example of working code:
def compileSdkVer = 30
def buildToolsVer = '29.0.3'
android {
compileSdkVersion compileSdkVer
buildToolsVersion buildToolsVer
defaultConfig {
...

Related

buildToolsVersion and compileSdkVersion had been deprecated

I've just noticed in a library module, that compileSdkVersion and buildToolsVersion had recently been deprecated. These are the two configurations, which it complains about (strikethrough text). This currently only affects com.android.library, not com.android.application:
plugins {
id "com.android.library"
}
android {
defaultConfig {
compileSdkVersion 31
buildToolsVersion "31.0.0"
}
}
When clicking through, on may notice that com.android.build.gradle.AndroidConfig had been deprecated in favor of BaseExtension (whatever that may mean for a matching build.gradle):
Apparently compileSdkVersion is now called compileSdk (this part seems to work) ...and buildToolsVersion has to be defined as a property. But when building (it's not that I've not tried), property buildToolsVerson = "31.0.0" is unknown:
android {
defaultConfig {
compileSdk 31
buildToolsVersion = "31.0.0"
}
}
How to make it build without deprecation warnings?
If you are using a kts gradle file instead (build.gradle.kts)
plugins {
id("com.android.library")
}
android {
defaultConfig {
// compileSdkVersion 31
compileSdk = 31
}
}
It builds alike this (the library module needs to be changed):
plugins {
id "com.android.application"
}
android {
defaultConfig {
compileSdkVersion 31
}
}
plugins {
id "com.android.library"
}
android {
defaultConfig {
// compileSdkVersion 31
compileSdk 31
}
}

Error while compiling: ERROR: Cause: compileSdkVersion is not specified

I wanted to compile my android studio project, somehow i ran into an error with firebase crashalytics. So I tried to fix the issue.
what I have now:
buildscript {
repositories {
...
maven { url = "https://maven.fabric.io/public" }
}
dependencies {
...
classpath "io.fabric.tools:gradle:1.25.1"
}
}
apply plugin: 'com.android.feature'
apply plugin: 'io.fabric'
So far so good, theoretically that should be it, from what I've read online. But I get an error now, ERROR: Cause: compileSdkVersion is not specified. so i googled this error, but all the solutions i found online where about the compileSdkVersion abd the targetSdkVersion differ.
compileSdkVersion 29
buildToolsVersion '29.0.2'
defaultConfig {
applicationId 'ch.workouttracker'
minSdkVersion 24
targetSdkVersion 29
versionCode 11
versionName '0.7.6'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "de" // And any other languages you support
}
so this is not the case here, what else should I try?

REACT NATIVE Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist

I'm getting this error in React Native.
This question says to put
ext {
compileSdkVersion = 26
}
in the 'top level file'. What is the 'top level file' for this in React Native?
module/build.gradle already has
android {
compileSdkVersion rootProject.ext.compileSdkVersion...
React Native android has two build.gradle files
// android/build.gradle
ext {
buildToolsVersion = "26.0.3"
minSdkVersion = 16
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
}
//android/app/build.gradle
android {
compileSdkVersion rootProject.ext.compileSdkVersion
}

I've two different react native packages which require different android compileSdkVersion, how do I fix this?

I use react-native-music-control and react-native-navigation(by wix) , rnmc requires compilesdkversion 23 and buildToolsVersion '23.0.1' whereas rnn requires compilesdkversion 25 and buildToolsVersion '25.0.0', rnn does not work with 25.0.0/25 and rnn won't work with 23/23.0.1 . I don't have much experience with android so I'm not sure how to fix this, any guidance would be great.
Add the following to build.gradle in your projects root directory
subprojects {
afterEvaluate {
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
targetSdkVersion 25
}
}
}
}

How to inject Android configuration to each subproject with Gradle?

Rather than duplicating the android configuration block in each of the sub projects:
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
}
I would much rather put this in the top-level/root gradle build file like:
subprojects{
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
}
}
However, this doesn't work. :(
Error:
"..Could not find method android() for arguments..."
The solution to this turned out to be:
subprojects{
afterEvaluate {
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
}
}
}
As far as I know, this is because to process/use the android{...} at evaluation time means it must be present (ie. explicitly written or included as part of an 'apply plugin') as soon as it hits the subprojects in the root build file. And, more accurately, it means that the top-level project must have it defined (which it likely doesn't because it might not be an 'android' or 'android-library' build itself). However, if we push it off to after the evaluation then it can use what is available within each subproject directly.
This question + solution also assume that all subprojects are some form of android project (in my case true, but not necessarily for others).
The safer answer would be to use:
subprojects{
afterEvaluate {
if(it.hasProperty('android')){
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
}
}
}
}

Categories

Resources