Unable to resolve dependency Android Studio 3.0 - android

It's good to have a Updated Android Studio 3.0. But I am facing a problem with Android Studio 3.0, I just created a new project in Android Studio 3.0. Then I got some error
I solved these by changing dependencies to latest version and issues solved.
But, when I added a dependency of facebook account-kit sdk com.facebook.android:account-kit-sdk:4.+
I am getting following errors-:
Error:Unable to resolve dependency for ':app#debug/compileClasspath':
Could not resolve com.facebook.android:account-kit-sdk:4.+. Open
FileShow Details
build.gradle(app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "ultimate.devil.logintest"
minSdkVersion 15
targetSdkVersion 26
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"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.facebook.android:account-kit-sdk:4.+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
NOTE -:
I am following Facebook Developers Docs
I have tried by changing compile to implementation
I have also tried changing com.facebook.android:account-kit-sdk:4.+ to com.facebook.android:account-kit-sdk:4.11.0 and com.facebook.android:account-kit-sdk:4.27 by googling latest version of Facebook Account-Kit SDK
I have also tries StackOverFlow Answers with possible with same problem. But no one help me
Screenshot

After some research I have solved this issue.
Step 1-:
I disable the Gradle offline work in settings.
File > Settings > Build, Execution, Deployment > Gradle > Uncheck Offline Work
Step 2-:
Then, I just changed compile 'com.facebook.android:account-kit-sdk:4.+' to api 'com.facebook.android:account-kit-sdk:4.+'
I don't know exactly why it's work. I see api in docs Reference
Now it works :)
EDIT -
Now, I am able to use both api or implementation and everything works fine.
Thanks,

Add matchingFallbacks = ['release', 'debug'] in the buildType that is failing to compile.
E.g. I was having an error for releaseStaging:
buildTypes {
debug {
buildConfigField "String", "CODEPUSH_KEY", '""'
}
releaseStaging {
buildConfigField "String", "CODEPUSH_KEY", 'myKey'
signingConfig signingConfigs.release
matchingFallbacks = ['release', 'debug']
}
release {
buildConfigField "String", "CODEPUSH_KEY", 'myKey'
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}

I am facing similar error day before yesterday. Just solved it here
Moreover, as mentioned in the latest gradle release notes , you should avoid using dynamic dependencies with version number as:
com.facebook.android:account-kit-sdk:4.+
Try to replace it with appropriate version number as 4.0.0 or latest. Hope it solves the problem.

Short story:
Downgrade to Gradle 4.2.1
Long story:
I was using Gradle version 4.3 based on the answer here as that question was my error. After doing that change than I started having your problem.
Downgrading to version 4.2.1 your problem went away. Now I have to go back to the previous problem.
I also had this problem while compiling my project with Android Studio 3.0 and gradle plugin 3.0.0
If I will have other problems I will post here the updates

all the Facebook Account Kit SDK build artifacts can be found on Maven Central:
// https://mvnrepository.com/artifact/com.facebook.android/account-kit-sdk
api 'com.facebook.android:account-kit-sdk:4.35.0'
and the according repository to add is:
repositories {
mavenCentral()
}
Gradle not being in offline mode, is being assumed.

I solve this problem by clearing this directory:
c:\Users\User name\\.gradle\caches\

I had the same issue and I solved it by changing apply plugin: 'com.android.application' to apply plugin: 'com.android.library'
Regarding my issue, it was a little bit different from yours. I have the second module with android library and from android developers page under the section "Convert an app module to a library module". My guess is that it is related to managing Manifest files inside of the architecture, so Android will know where is the main Manifest file.
And regarding api and implementation, the answer can be found here
The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.

Had the same issue. After trying everything, finally realized that it was the network that didn't allow syncing dependencies. Tried out with hotspot and it worked.

I had the same issue and I did fix it like this :
implementation project(path: 'com.facebook.android:account-kit-sdk:4.+', configuration: 'default')

Downgrade these two files solve the problem
project`s build.graddle to 3.1.4
graddle-wrapper properties to 4.4

Saw an old project. It showed "build" successful. So i checked build.gradle file. Comparing those 2 projects i saw a change in dependencies version number. Then i just copied version numbers from the old proj and it worked. There was one more BuildUsing or so in android{} i removed it from my new proj (it was not in my old proj). i think it is because of an incomplete or corrupt gradle update.

Related

Android Studio: No build variant found error

i am new to android development, i started developing from scratch on a project i bought online, following the documentation, i encountered a error saying No variants found for 'app'. Check build files to ensure at least one variant exists.
Here is the build.gradle code
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.app-10.app"
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'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Third Party Libraries
//Glide library for image fetching from the web
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//Material library for styling blocks
implementation 'com.google.android.material:material:1.0.0'
// Google Gson
implementation 'com.google.code.gson:gson:2.8.5'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
// Android-SpinKit
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
implementation files('libs/YouTubeAndroidPlayerApi.jar')
// gotev/android-upload-service
implementation "net.gotev:uploadservice:3.5.2"
//A fast circular ImageView perfect for profile images
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'org.apache.commons:commons-io:1.3.2'
}
I have just solved the same issue like this:
Tools -> SDK Manager
Verify that the SDK platform package for Android 10.0 (the one with API level 29, like you defined in your gradle file) is checked.
If not, check it and apply changes. Accept the licence terms, install the package and then File -> Sync Project with Gradle Files (or open the project again)
In my case, it is because I add flavourDimensions and not adding it to any productFlavors
example from my case I have in my build.gradle in app level:
flavorDimensions "stage", "mode"
and my productFlavors:
productFlavors {
dev {
dimension "stage"
//noinspection DevModeObsolete
minSdkVersion 21
versionNameSuffix "-dev"
applicationIdSuffix '.dev'
resConfigs "en", "xxhdpi"
}
prod {
dimension "stage"
minSdkVersion 21
versionNameSuffix "-prod"
applicationIdSuffix '.prod'
}
}
As you can see here, I don't use flavorDimensions "mode" in any of my productFlavors's dimension. So, when I try to sync my gradle. It gives me that error.
So my solution here is to remove "mode" from flavorDimensions
go to the SDK manager (Ctrl+Shift+A then write SDK manager), install the android version of current project, in this case I installed all the available options starting from 5.0
I replaced from:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
to my Android Studio v3.0.1 in my case:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
but at the end i resolve it by
you need to detect and set your proper sdk
my sdk is 30.0.2 after i install 29.0.2 this error gone
Might help someone, in my case, I just needed to update Gradle.
A warning popped up on Android Studio, so I updated it, and then worked properly 🤷🏻‍♀️
For me the issue was that I hadn't opened the project at its root folder, I'd opened the "app" folder. Both folders had the gradle icon so it was an easy mistake to make after not having done any Android development for a while.
You may get the "No variants found" error in a project with multiple modules, when build types do not match between modules.
In my case, this happened when trying to add a macrobenchmark to an existing Android project.
Following the instructions in this document, I added a new module macrobenchmark to the project.
At some point, I misinterpreted the instructions: I added a new build type benchmark to the build.gradle of module app, but did not add the same build type to the build.gradle of module macrobenchmark.
From then on, any attempt to sync the project with the gradle files would fail with the following error message:
No variants found for 'macrobenchmark'. Check build files to ensure at least one variant exists.
The solution was simple (but not trivial): bring the build types back in sync. In my case, add the missing build type benchmark to the build.gradle of module macrobenchmark.
Try with
npm i cordova-android#10.1.1

Understanding WHY gradle complains about colliding versions

I have been trying to bring back an old app of mine, that I wrote a while back using eclipse. I imported to android-studio and I it complains about colliding versions:
All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found
versions 28.0.0-alpha1, 27.1.0. Examples include
com.android.support:animated-vector-drawable:28.0.0-alpha1 and
com.android.support:cardview-v7:27.1.0
At first, I solved it as suggested by this question, by including the colliding packages specifically in the gradle file with the newer version. So my gradle file ended up like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.tomklino.imhere"
minSdkVersion 16
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:+'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:customtabs:27.1.0'
implementation 'com.android.support:support-media-compat:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation "com.google.android.gms:play-services-gcm:11.8.0"
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
}
apply plugin: 'com.google.gms.google-services'
}
This removed the red line from under the appcompat line, but then, after debugging something else, I got the message above again, but this time with the version 28.0.0-alpha1. Now I can't include the new version, because if I try it says it is incompatible with the sdk version of 27.
I'm trying to understand why it asks for that version in the first place if I havn't included that sdk version anywhere. Nothing in the dependency tree asks for the 28.0.0-alpha1 version specifically.
but then, after debugging something else, I got the message above again, but this time with the version 28.0.0-alpha1
Replace:
implementation 'com.android.support:appcompat-v7:+'
with:
implementation 'com.android.support:appcompat-v7:27.1.0'
and resolve to stop using + for the entire version of an artifact.
I'm trying to understand why it asks for that version in the first place if I havn't included that sdk version anywhere.
You used + for the version of appcompat-v7. This says that you want the latest that Gradle can find. And, last week, Google released 28.0.0-alpha1, in tandem with the release of the Android P Developer Preview 1.
I had the same issue, but no of dependencies had '+' in version number.
Problem was in xwalk (Crosswalk WebView) library.
I've solved it by adding 'transitive':
compile ('org.xwalk:xwalk_core_library:23.53.589.4') {
transitive = true;
}

Add AppCompat dependency to Gradle in Android Studio

Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat.
Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"
But it returned an error saying that "Task 'compile' is ambiguous...." in my project.
Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.
Thanks!
Have you been able to locate Gradle file?
Edit your gradle like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.00.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
Update your question and post full Gradle code.
Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file
Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy
Task 'compile' is ambiguous.
This issue is not the Compile Issue. but this was an issue on the task itself.
if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.
Here is a link that seems to relate specifically to your issue. Click Here

Compilation errors with Gradle, Android Studio and Butterknife

I've imported Eclipse Android project to Android Studio and it fails to compile with following errors:
Error:(7, 8) error: duplicate class: com.company.fragment.PrimaryFragment$$ViewInjector
I've tried adding apt plugin:
apply plugin: 'android'
apply plugin: 'apt'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
disable 'InvalidPackage'
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
compile project(':library')
compile 'com.android.support:support-v4:+'
apt "com.jakewharton:butterknife:5.1.1"
compile 'com.jakewharton:butterknife:5.1.1'
}
I think that this has something to do with Butterknife. But when I make a clean project with it, everything is ok.
If you still have the target/build folders from eclipse in your build directory it might be a good idea to delete those.
Also Cleaning project under Project -> Clean might help.
Also if you are running maven or gradle from command line, it would be wise to run:
maven clean
or
gradle clean
You don't need both the apt and the compile dependency, only the compile dependency.
By having it twice, the annotation processor is running twice (with two different output directories) which means the generated classes are created twice. The error you are seeing is because there are two identical classes being generated for your PrimaryFragment.
The apt scope (and plugin) are only needed for libraries which separate their runtimes from their annotation processors (sometimes called compilers). An example of this would be Dagger which has a dagger and dagger-compiler.

Android Studio can't find imported library

I've imported a library in Android studio (0.5.3)
My settings.graddle looks like this:
include ':app', ':libs:Android-PullToRefresh-master'
And my build.graddle looks like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile fileTree(dir: 'libs', include: ['*.jar'])
project(':libs:Android-PullToRefresh-master');
}
The folder I've downloaded is placed in the libs folder directly under the app folder. Also the graddle syncs and building doesn't provide any error. Yet whenever I try to import import com.handmark.xxxxxx; I get the error cannot resolve symbol 'handmark'. I've chcecked to project structure and the app has the dependency in the list.
What is going wrong and how can I fix this?
I ran into the same issue here and asked the question on the "Android Developer Tools" Google+'s community. Alex Ruiz picked up the conversation and told me:
I'm able to reproduce this issue. Unfortunately, no updates yet. We
are currently fixing the "Project Structure" (the core
infrastructure,) and we will get to this, hopefully soon.
So they are aware of it but we still have to wait until they fix it.
In the root of your project, run :
./gradlew clean && ./gradlew build
Then recompile your project in studio and you should see your new lib.
I had the exact same problem as this, however the library file was an aar file, and it happened a long time after adding the library and developing with it for a while.
Building on the information Thomas provided; I found to fix this you should replace the file dependency with a maven dependency if possible. A good resource for finding and creating your Gradle dependency is Gradle, please.
That site returns the below dependency when searching for PullToRefresh
dependencies {
compile 'com.loopeer.android.thirdparty.pulltorefresh:Android-PullToRefresh:2.1.1'
}

Categories

Resources