Android Resourcse linking Failed while using : buildFeatures {viewBinding = true} - android

After starting an android studio today, I came across a strange problem. It was saying
DSL element 'android.viewBinding.enabled' is obsolete and has been
replaced with 'android.buildFeatures.viewBinding'.
After searching for a bit I found out that I had to use
buildFeatures {viewBinding = true}
instead. So, I replaced viewBinding{enabled=true} with the above one. After that, the real problems started. AAPT can no longer detect my drawables. Here is my buildScript:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.techtrixbd.RestaurantApp"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {viewBinding = true}
}
I don't know what is going on anymore. Any advice will be a big help.

I have solved the issue. I had to move my resources to drawable-v24 folder. that's it. But, don't why it was required because everything was working fine yesterday. Maybe an update has something to do with it. I will look for the cause and will post if I come up with something.

Related

Firebase referencing old database

I set up a Firebase realtime database in an Android app, but I chose the wrong location, so I deleted the Firebase project. I then made a new project and did the exact same steps (yes, I did swap out the google-services.json file). However, when I try to access the database, through FirebaseDatabase.getInstance() for example, it still refers to the old project (which I can tell by the project id).
Also, when I do FirebaseApp.getApps(), it only contains the app with the "old" project id. After this didn't work, I did it all over again on a new branch, and it somehow still refers to the old project. I can see the correct project id in the google-services.json file, why is it not using it?
Project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath 'com.google.gms:google-services:4.3.4'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Relevant module gradle:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "test"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation platform('com.google.firebase:firebase-bom:26.1.1')
implementation 'com.google.firebase:firebase-database:19.6.0'
}
Just try out this simple solution..
remove the old google-services.json from your project.
uninstall previous version of your app in device/emulator.
place new google-services.json
clean and rebuilt before launching it to device.
hit run.

Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'

i tried everything i could think of but i keep getting this error.
this is my gradle build:
buildscript {
repositories {
jcenter()
maven{ url "https://dl.bintray.com/android/android-tools" }
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath 'com.google.gms.google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven{url 'https://www.google.com/'}
maven { url "https://dl.bintray.com/android/android-tools" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.example.textbookexhange"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
my gradle wrapper is fine
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip
The reason you are not able to resolve the version 4.0 because the version 4.0 is not available in the JCenter.
https://jcenter.bintray.com/com/android/tools/build/gradle/
Firstly the version 4.0 should be available in your Bintray package in order for it to mirror in the JCenter You can check the same in the below bintray download link:
https://dl.bintray.com/android/android-tools/com/android/tools/build/gradle/
Update the version 4.0 under the path "com/android/tools/build/gradle" in your bintray package so that it will be reflected in the JCenter.

Android DataBinding build error

I have a problem with Data Binding library for Android.
I have a freshly installed Android Studio v2.0 and newly created project.
The problem is that when I try to add
dataBinding {
enabled = true
}
to my build.gradle, I get this error while trying to build the project:
:app:dataBindingProcessLayoutsDebug FAILED
Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'.
Could not initialize class android.databinding.parser.XMLLexer
The build.gradle files look like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "com.silgrid.test"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
}
Does anyone know how to fix this?
Thanks.
Updating gradle version in main gradle file has solved this problem for me.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "com.android.databinding:dataBinder:1.0-rc1"
classpath 'com.google.gms:google-services:4.1.0'
}
}
For me it got fixed after updating to Android Studio 2.2

Android databindingError:Cannot change dependencies of configuration ':mobileBanking:compile' after it has been resolved

I'm having a lot of trouble adding databinding to my project. There is a complicated build.gradle. Unfortunately, I cannot post too much from it.
If I add databinding {enabled = true} to my android block in my app build.gradle file I get the following error -->
Error:Cannot change dependencies of configuration ':projectName:compile' after it has been resolved.
Cannot get property 'javaCompile' on null object.
I've added the databinding library on my classpath. If I don't add the dataBinding {enabled = true} block the build succeeds with a warning that generated sources are in the wrong folder.
Any ideas?
Here is my sample build.gradle with databinding enabled. I'm using this setup in my projects and databinding is working fine. Notice that you only need to specify databinding {enabled true}. No more setup is required. You don't have to add databinding to dependencies.
build.gradle from main folder
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
subprojects {
buildscript {
repositories {
jcenter()
mavenCentral()
}
}
repositories {
jcenter()
mavenCentral()
}
}
build.gradle from app
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "foo.bar"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//support library
compile 'com.android.support:appcompat-v7:23.1.1'
}

android- Gradle: An issue occurred configuring root project android studio

I migrated from eclipse to android studio. I've create a new project and I want to run it on genymotion. When I press run icon, it begins to compile and give me this error :
Error:Gradle: A problem occurred configuring root project 'Khabar'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:1.1.0.
Required by:
:Khabardar:unspecified
> Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.1.0/gradle-1.1.0.pom'.
> d29vzk4ow07wi7.cloudfront.net
This is some parts of my build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "example.ir.khabar"
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
build.gradle in root :
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "example.ir.khabar"
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'
compile files('libs/universal-image-loader-1.8.4-with-sources.jar')
}
Could you help me? my gradle version is gradle-2.2.1-all
For me, the solution was to add the http url for jcenter, instead of https:
buildscript {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In addition to Al's answer, I also had to put the url inside allprojects:
allprojects {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
I was having the same issue on Ubuntu Mate 18.04. I was able to fix it by replacing ibm-java80-jdk & ibm-java80-jre with openjdk. Also, I did update my DNS to cloudflare DNS. But I don't think it had anything to do with the fix.
add google() in your gradle inside the repositories section will solve your problem..
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}

Categories

Resources