Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

enter image description here

What is wrong here?

Though it works fine for libraries in the same project:

enter image description here

Also everything is fine for the next lines in defaultConfig block

minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion

enter image description here

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

like image 597
user924 Avatar asked Oct 06 '18 07:10

user924


1 Answers

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.

List of project candidates reported by IDE

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
    ...
like image 52
Saeed Masoumi Avatar answered Nov 02 '22 23:11

Saeed Masoumi