Gradle settings: Invalid variable name. Must start with a letter but was: - android

Had a issue during settings of my android project:
startup failed:
settings file '/home/user/StudioProjects/project/android/settings.gradle': 1: Invalid variable name. Must start with a letter but was: rootProject
. At [1:1] # line 1, column 1.
rootProject.name = 'project'
^
1 error
Open File
But the thing is I don't have any symbols before 'rootProject' variable name.
Any thoughts about it?

If you're trying to setup some global variables in your root gradle files then reuse them in your modules' build.gradle, how I got it working was:
in ROOT build.gradle :
buildscript {
... blah blah
}
// put HERE all your variables, they will automatically
// be available as rootProject.xxx in the rest of build.gradles
ext {
name = "project"
compileSdkVersion = 27
targetSdkVersion = 27
supportLibraryVersion = "27.0.2"
buildToolsVersion = "26.0.1"
googleServicesVersion = "11.8.0"
}
allprojects {
... blah blah
}
.
.
And then in your APP (or modules) build.gradle, you can use them:
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "xxxx"
targetSdkVersion rootProject.targetSdkVersion
.
.
}

I got the same error when i moved my project into a different path.
I tried to do Invalidate Cache/Restart but, it did not work for me.
I finally deleted build.gradle (project level) and opened Android Studio.
It errored out saying 'This is not a gradle based project'.
Then i created the build.gradle, put the contents back and clicked on 'Make Project'. It seemed to work fine then.
Not sure, if this will work for you. But you can give it a shot.

Related

The data is invalid. (13) . AAPT2 . file missing

One of the autogenerated files (R file) is showing missing while building the project.
ext.kotlin_version = "1.5.0"
classpath 'com.android.tools.build:gradle:4.2.0'
compileSdkVersion 30
buildToolsVersion "30.0.2"
minSdkVersion 21
targetSdkVersion 30
Answer Update :
The Antivirus was interfering and capturing the autogenerated file as false positive.
Ignoring the file or Add to exception or Allowing the Program in antivirus solved the problem.

Importing older gradle projects into android studio

How do i import a project downloaded from github which is based on an older gradle version (2.0.0)?
here is my build.gradle-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
ext {
compileSdkVersion = 23
buildToolsVersion = "23.0.3"
minSdkVersion = 14
targetSdkVersion = 23
}
whenever i change the gradle version to 2.1.2 (which is the gradle version used by all my projects), the project gets stuck on the "building.." message and never imports-
classpath 'com.android.tools.build:gradle:2.1.2'
I even tried replacing the whole build.gradle file with the one in my projects, and still no luck.
This is what i do after importing project from Github
There are two gradle files as shown is picture
In first gradle file replace class path with yours
classpath 'com.android.tools.build:gradle:2.1.2'
now in other gradle file as shown in figure
replace these below lines with yours
compileSdkVersion 23
buildToolsVersion "23.0.2"
and
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
If there are dependencies on libraries than you would require to change them too
Also try to check root gradle file and properties.
Use default gradle wrapper . It could be found in File->Settings ->Build->Build Tools->gradle.
disable InstantRun though its require but could be helpful sometimes.
Try this .

Error:Cause: buildToolsVersion is not specified

I create a simple project and then I right-click on the project and then I use the make mudole app option. Now I have two build.gradle folders: 1- build.gradle:project My Application. 2- build.gradle: Mudole app. the first build.gradle is as follows:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.library'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
And the second Build.gradle folder is as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.exam.exam.myapplication"
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And now I click on the run option to create aar file from this project But I get the following error:
Error:Cause: buildToolsVersion is not specified.
I had the same issue. What I was doing wrong was the placing of apply plugin statement in the root gradle of the project. When I placed it in the app gradle then the issue got resolved.
What I would suggest is to check if you are placing some statement in the root gradle that you should be placing in the app gradle.
Add buildToolsVersion to your build.gradle file this will solve your problem.
buildToolsVersion "27.0.1"
Gradle file code
android{
compileSdkVersion 27
buildToolsVersion "27.0.1"
useLibrary 'org.apache.http.legacy'
}
Add buildToolsVersion property to your local build.gradle file.
android {
compileSdkVersion 27
buildToolsVersion "26.0.1"
defaultConfig {
targetSdkVersion 27
}
}
As per your requirements!! Then Try to build -> you will get build failure and this message :
Failed to find Build Tools revision 26.0.1
Install Build Tools 26.0.1 and sync project
Then Click to Install build tools and your project is configured and you are good to go!!!
in file... build.gradle(Project: XXX):
repositories{
//put pluging repository here
//e.g.:
mavenCentral()
}
dependencies{
//classpath to plugin here
classpath 'com.XXXX.xXXxxXX.XXXX'
}
in file.... build.gradle(Module: app)
//add on top:
apply plugin: 'com.YOUR.PLUGIN.XXX'
The issue for me was that andorid-versionCode can only be integer value.
in build.xml:
eg:android-versionCode="1"
It cannot be "1.1" etc...
The error code is not helpful at all.
Not really sure what the underlying problem was, but I found the solution in a concurrent problem that was occurring:
https://stackoverflow.com/a/32490472/1544046
Essentially, I had to change my gradle target to use the wrapper and not a defined path. I've had it set to the Gradle Wrapper in the past, but it seems to revert from time to time without notice. Once I switched back and recompiled it worked fine.
In the project's settings: Build, Execution, Deployment->Build Tools->Gradle and select "Use default gradle wrapper".
Might be helpful for someone:
in my case long time ago I had added keystore properties in build.gradle file for Android:
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
and after some period of time I pulled repo and forgot to add this file ("keystore.properties").
Gradle for some reason (!) gave me the same error (buildToolsVersion was defined a bit below in build.gradle file).
The workaround was just to add missing "keystore.properties" file.
Android Project > setting.gradle
include ':app' , ':xxx'
I imported one of module and this coused this error. I remove it is fixed.
include ':app'
Check if android studio version in build.gradle is same as the one you are running.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In my case, I opened/imported the project created on android studio 2.3.3 in android studio 3 and i was able to get rid of this issue after updating the build.gradle with 3.0.0
for me it was an additional classpath line for example :
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
so i was deleting the first
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
and the issue solved
I had same error, I using cordova and resolve by removing the space character
id="com.xx.yy " => to id="com.xx.yy"
Try to invalidate caches / restart , it fixed this like this after updated
File-> Invalidate caches/restart

Android Studio 1.0 and error "Library projects cannot set applicationId"

After updating Android Studio to 1.0, I see this error:
Error: Library projects cannot set applicationId. applicationId is set
to 'com.super.app' in default config.
I updated the Gradle plugin as suggested but I did not understand how to fix this.
Based on this info:
ApplicationId in Library Projects
You cannot use applicationId to customize the package of a library project. The package name has to be fixed in library projects (and specified as packageName in the manifest). The Gradle plugin did not enforce this restriction earlier.
Removing applicationId variable from the library's build.gradle file should resolve the issue.
Thanks to Joel for his correct answer: I need to remove only 1 line from te .gradle file:
defaultConfig {
applicationId "com.super.app" <---- remove this line
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
becomes
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
and my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.super.app">
...
This is the right solution if you don't need to rename the package name of your app. To rename it you need to use "flavours":
android {
...
productFlavors {
flavor1 {
applicationId 'com.super.superapp'
}
}
Libraries can't set applicationId and if you are working in a multi-module project and picking up flavors from a separate file , none of the above answers will work. For a modularized app, you need the following steps -
Create a flavors.gradle file in project root directory
ext.flavorConfig = { // 1
flavorDimensions "pricing"
productFlavors {
free {
dimension "pricing"
ext.myApplicationIdSuffix = '.free' // 2
}
paid {
dimension "pricing"
ext.myApplicationIdSuffix = '.paid'
}
}
productFlavors.all { flavor -> // 3
if (flavor.hasProperty('myApplicationIdSuffix') && isApplicationProject()) {
flavor.applicationIdSuffix = flavor.myApplicationIdSuffix
}
}
}
def isApplicationProject() { // 4
return project.android.class.simpleName.startsWith('BaseAppModuleExtension')
}
In 1 we export a closure so that we can use it in our modules’ build.gradle files.
In 2 we define a custom myApplicationIdSuffix property. We cannot simply have applicationIdSuffix as it is not possible to use it in library modules (build would fail if you did).
In 3 we iterate over created flavors and set applicationIdSuffix if we detect that it’s an application module only.
4 is a way to check where this closure is being used.
All that’s left is to use this closure in our modules’ build.gradle files. E.g. in application module this would look like this:
apply plugin: 'com.android.application'
apply from: "${rootProject.projectDir}/flavors.gradle"
android {
// other config...
with flavorConfig
}
If this isn't clear, you can check out this article for better understanding.
Just incase it helps some one :
When i imported an eclipse project into android studio,i got an error ::
"Error:Application and test application id cannot be the same"
Strange though,but i looked into the build.gradle and found the two placeholders,one for the application and other for testapplication.
I removed the testApplicationId from that as is suggested in this post and this helped me resolve the issue.
Note: This explaination is not related to the errors posted in this question,but might help someone who is getting a similar error.
You cannot define applicationId for your lib.
But incase you want to use an identifier in your build file, which will give you, your library package name, you can define a variable for the module and then use the value as required.
eg : Library's build.gradle
apply plugin: 'com.android.library'
def libraryGroupId = 'com.google.example'
def libraryArtifactId = project.getName()
def libraryVersion = '1.1'
Also, you can use the value below as needed in your build file itself in lib.
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "$libraryVersion"
resValue "string", "Library", libraryGroupId"
}
}

Execution failed for task :appprocessDebugManifest. Manifest merging failed. See console for more info

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
}
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
Still no luck after much researching. I change the version number, and the android manifest matches the minSdkVersion and targetSdkVersion as the build.gradle file above. No idea why this doesn't work?!?
In gradle build system minSdkVersion and targetSdkVersion defined in AndroidManifest.xml file will be replaced by what you have mentioned in build.gradle file.
If you are using multiple modules or libraries in your project make sure all build.gradle files as well as AndroidManifest.xml files having same set of configuration for minSdkVersion and targetSdkVersion.
UPDATED
It might possible that any library like google_play_services or other is using different minsdkVersion .
Check your Gradle Console output and make the required changes in your AndroidManifest.xml files as well as in build.gradle files. Also take care that all your build.gradle and AndroidManifest.xml files should have same minsdkVersion. I tried with different values and finally found that most of the libraries uses minSdkVersion 8 .
Also for better practice you can remove min and target sdk from Manifest and have them in build.gradle file only for minimal confusion.

Categories

Resources