ERROR: Failed to resolve: fragment Affected Modules: app - android

I'm working with Android Studio version 3.5.3. The problem is when I want to create project with Java, I have the Error for Failing to resolve fragment and the same error for Activity. But I don't have the problem when I create project with Kotlin. you can see the Gradle file below.
Project Gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App Module Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
there is the error Log.

I've solved my problem by updating the Gradle version from 5.4.1 to 6.0.1.
By the way, It should work with the previous Gradle version base on Google Document. But it has a problem with Java application.
You can find plugin version Android studio with the required Gradle version in this image.

Related

Android Studio - Gradle project sync failed ,ASCII error occurred

The problem is that when I sync a project on Android Studio. I followed all the steps on the Fire base guide, the "ASCII" error occurred.I already paste my google-services.json file is in the app folder.
build.gradle(Project: )
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.anikr.communityapp"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
}
apply plugin: 'com.google.gms.google-services'
Add following line to gradle.properties
android.overridePathCheck=true
use classpath 'com.google.gms:google-services:4.2.0'
and remove firebase-analytics dependency.
This resolved my errors.
Add following line to gradle.properties(project properies)
android.overridePathCheck=true

ERROR: Failed to resolve: play-services-basement

I have added Firebase messaging to my app using firebase tools in Android studio and I faced a problem in my app (there was no error before adding firebase messaging). My current setting in App level gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 15
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services'
I have updated all dependencies using project struture menu to latest versions. As I write this question the latest version for firebase-messaging is 20.0.0 and for com.google.gms:google-services:4.3.2 so the problem is not about updating to latest versions.
This is Project level gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://jitpack.io'
}
maven {
url 'https://maven.google.com'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have checked this Q/A but this is not my case as I have google() in repository before everything else. Also as I am working in androidx environment the case is not about support.v4.
When I rebuild the project I get this error:
ERROR: Failed to resolve: play-services-basement
Affected Modules: app
The error was gone by adding the following line manually to the dependencies of APP gradle:
implementation 'com.google.android.gms:play-services-basement:17.1.1'
I wonder why should a programmer know all background dependecies of a package and why they are not implemented automatically.

Unable to resolve error of gradle version when migrating to AndroidX

When I tried to migrate my own project to AndroidX, the error message appeared on a error dialog:
The gradle plugin version in your project build.gradle file needs to be set to at least com.android.tools.build:gradle:3.2.0 in order to migrate to AndroidX.
Then I googled this error on the Internet. A site was found that it said classpath 'com.android.tools.build:gradle:3.2.0' has to be added to the build.gradle. Therefore, I added the line to the build.gradle like this:
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:support-core-utils:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
However, the same error happened. Am I missing something?
Check your build.grade of Project level ( Not Module )
And change the version of the android gradle plugin:
buildscript {
...
dependencies {
...
classpath 'com.android.tools.build:gradle:3.4.1' // it should be more than 3.2.0
}
}

how to handle this problem of"inconsistencies in the existing project dependencies found" when trying to add a grid layout

while dragging and dropping the grid layout into the design of my app,I get the following message:-
This operation requires the library com.android.support:gridlayout-v7:+.
Problem: Inconsistencies in the existing project dependencies found.
Version incompatibility between:
- com.android.support:appcompat-v7:28.0.0
and:
- com.android.support:appcompat-v7:28.0.0
With the dependency:
- com.android.support:support-annotations:26.1.0
versus:
- com.android.support:support-annotations:28.0.0
The project may not compile after adding this library.
Would you like to add it anyway?
What should I do???Please help.
i have only 7 days of experience with android.
I am using android 3.4.1 for Windows 64-bit.
Below are the gradle dependencies:-
classpath 'com.android.tools.build:gradle:3.4.0'
The app gradle is:-
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.connect3"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
and this is the other one that has the project name on it:-
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

android studio failed to resolve: runner and failed to resolve: espresso-core and failed to resolve: monitor

I installed android studio 3.1.3 and when I tried to build a new application .. During the gradle synchronization I had a problem as in the following picture:
Failed to resolve: espresso-core
Open File
Failed to resolve: runner
Open File
Failed to resolve: monitor
Open File
and that is my app(build.gradle):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.tareq.ds"
minSdkVersion 28
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
and that is my project(build.gradle):
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Follow these steps:
Open Module setting for the application
Under dependencies, tab Click on '+' Symbol and add all the required
dependencies one by one
Click on Apply button

Categories

Resources