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

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.

Related

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

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.

Gradle: DSL method not found: minSdkVersion / targetSdkVersion / compileSdkVersion / buildToolsVersion

As it took me some time to find the solution for this error, I post my problem and solution here in the hope that I find it next time faster:
Error:(39, 0) Gradle DSL method not found: 'minSdkVersion()'
What I tried to do:
I followed the Android Test Blueprint's sample to define the library versions in the top level / rootProject'S build.gradle file:
ext {
minSdkVersion 16
}
And wanted to use it in the app's/module's build.gradle file:
minSdkVersion rootProject.ext.minSdkVersion
After half an hour or so I notices that this was a simple typo -.-
Solution
Add the "=" sign when you define a variable, else, Gradle thinks you call an Android method which it does not yet know in the top level build file:
ext { minSdkVersion = 16 }

Phonegap Build Error with multidex dependency

I'm trying to export my apk but I'm receiving one build error below:
I've added compile 'com.android.support:multidex:1.0.1' in my build.gradle dependencies, enabled multidex in my defaultConfig and also added android:name="android.support.multidex.MultiDexApplication"> within my Android Manifest file but am still receiving the error.
===============================
My build.gradle can be found here:
http://pastie.org/10902207
================================
What is going on? Can anyone give me some insight as to why I am receiving this?
I imagine the issue you are having is because you do not have a minSDK defined in your Build.gradle. The library you are trying to uses minSDKVersion 4.
If you don't specify your minSDKVersion your project is going to automatically default to version 1. Try adding something like the below to your build.gradle file.
android{
compiledSdkVersion 23 //marshmallow
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 11 //honeycomb
targetSdkVersion 23
}
}

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 .

build.gradle file errors and warnings after upgrade to Android Studio 1.5.1

Here's my build.gradle file. After updgrading to AS 1.5.1 and attempting to compile/sync, I got error on last line, but program executes fine:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.dslomer64.wordyhelperton"
minSdkVersion 19
targetSdkVersion 19
versionCode 16
versionName "3.02"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.1'
}
The error is on the last line above (compile 'com.android....-v4:22.2.1).
It says:
This support library should not use a different version (22) than the
compileSdkVersion (19).
So I changed compileSdkVersion to 22 and also changed minSdkVersion and targetSdkVersion to 22 since the first change alone still gave warnings, but NO ERRORS.
The warnings are on every line from 'defaultConfig' down.
The warning is:
defaultConfig cannot be applied to groovy.lang.Closure ... assignment with incompatible types
What should I do? App compiles and runs fine. Is ignoring these warnings are OK?
Yes, messages like ...cannot be applied to groovy.lang.Closure can be ignored, but if you want to fix them here are a few answers that will help you:
Quick fix - just a small change in settings.
Proper and lengthy fix - creating a top level build.gradle.
Missed this earlier but thanks to Gabriele for pointing it out in the comment below:
The warning about the api to be used to compile the project, should
not be ignored. You have to compile with the same version of the maior
release (in this case 22) otherwise you can have issue. For example
using the appcompat v22 you would have errors using api 19
Those warnings can be ignored, I have them throughout my projects as well.
I have a top level gradle.build file and reference some parameters from it in lower level gradle.build files. I think that is where the error comes from in my case. Gradle can't tell what argument type it is.
As it turns out, I guess because of upgrade, the folder previously containing Gradle wasn't found. I changed it to C:\Program Files\Android\Android Studio\gradle\gradle-2.8 and all was well except for two warnings, both suggesting using latest version of Android, so I made the suggested changes (new Gradle.build file below) and have no warnings:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.dslomer64.wordyhelperton"
minSdkVersion 19
targetSdkVersion 23
versionCode 16
versionName "3.022"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.1.1'
}
I also changed Build, Execution, Deployment to have Gradle use the default Gradle wrapper instead of the local specific folder (2.8 as reported above) as discussed here.

Categories

Resources