Unresolved dependencies error in IntelliJ IDEA - android

So i just started working with IntelliJ and created my first project, but i get this error in the Messages make
and this in the Event log
this is the content of my my build.gradle file
Can someone please help?

Try this in your Gradle build file:
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
}
Your one dependency (of the form groupId:artifactId:version) is not quite right. You have the version listed as just +. Instead, it needs to be 18.0.+, which specifies a release version of 18.0.0 or greater.
See here for details.

Related

Android dependency has different version for the compile and runtime classpath

I am using a lot of Firebase related libraries in my project. Upon syncing, I am facing the following error.
Android dependency 'com.google.firebase:firebase-iid' has different
version for the compile (17.0.3) and runtime (17.1.1) classpath. You
should manually set the same version via DependencyResolution
The thing is that I have not even declared firebase-iid in my dependencies and this is coming as a transitive dependency from other firebase libraries.
Upon running the dependency chart, I am able to find the following things.
Version 17.0.3 is coming from com.google.android.gms:play-services-measurement-api:16.4.0
Whereas 17.1.1 is coming from com.google.firebase:firebase-messaging:17.5.0
Ideally it should resolve it internally and the higher version should be automatically picked. But this is not happening.
Any idea why this is happening and how to resolve this issue?
There is not updated gradle for com.google.android.gms:play-services-measurement-api:
The latest release is on March 2019, version : 16.4.0 .
So, your implementation is not correct for this measurement-api .
Use :
com.google.android.gms:play-services-measurement-api:16.4.0
com.google.firebase:firebase-messaging:17.5.0
refer this link : https://mvnrepository.com/artifact/com.google.android.gms/play-services-measurement-api/16.4.0
https://mvnrepository.com/artifact/com.google.firebase/firebase-messaging
Yes you are right, gradle should automatically resolve to a single version of a library, but as I experienced sometimes, it does, sometimes, it does not. But when It does not resolve to a single version of same library, we can force it to use a single specific version like explained below.
configurations.all {
resolutionStrategy {
force "com.google.android.gms:play-services-measurement-api:17.1.1"
force "com.google.firebase:firebase-messaging:17.5.0"
}
}
dependencies {
// ... all dependencies here...
}
Try using above code forcing gradle to use a single version. Might help in your case.

Android studio automatically tries to update libraries?

In my project I have many libraries defined in dependencies section in gradle. Problem is once in a while (once/twice a day)Android Studio gives me errors like this when opening the project or trying to get a release output:
Error:Unable to resolve dependency for ':TMessagesProj#armv7Debug/compileClasspath': Could not resolve com.google.android.gms:play-services-gcm:11.2.+.
My guess is it is because build tools is trying to check if there is an update for each library and when it doesn't find an Internet connection, it shows this error. If so, how can I change the setting in a way it doesn't have to check for updates? In other words in my project I don't need to update my libraries.
I know there is an offline mode that will probably do the trick! But I don't want to use this feature because it will probably disable some other useful features too. I just want to prevent it from automatically checking for library updates(If that's the problem shown above).
I included some part of my dependencies in gradle here:
dependencies {
compile 'com.google.android.gms:play-services-gcm:11.2.+'
compile 'com.google.android.gms:play-services-maps:11.2.+'
compile 'com.google.android.gms:play-services-vision:11.2.+'
compile 'com.google.android.gms:play-services-wallet:11.2.+'
}
Dependencies with a plus like 11.2.+' will always lead to repeated builds.
You have to specify the full version like:
com.google.android.gms:play-services-gcm:11.2.0
If you do not specify gradle will always be building because its looking for the latest version online of 11.2.+ may be 11.2.4, 11.2.6 etc

How to get a compile error if a JAR dependency is missing?

I have an Android project with the following dependencies:
-- Android App
---> MySDK.Jar
------> 'org.apache.commons:commons-lang3:3.5'
This is MySDK.jar that has a dependency on commons-lang3.
I'm working on Android Studio and I'm thus using Gradle.
Here is my problem:
I have shared "MySDK.Jar" to someone and he has built his own Android App on top of it.
It works but we have seen that the compiler doesn't notice the missing dependency on 'org.apache.commons:commons-lang3:3.5'. At run-time there will be a crash if the code using 'org.apache.commons:commons-lang3:3.5' is called. One may not notice the problem if he doesn't call the code using this library.
I know that we can solve this issue by adding the following line to Android App build.gradle file:
compile 'org.apache.commons:commons-lang3:3.5'
I'm wondering if there is a way to get a compile error indicating such missing dependencies? It is indeed better to see the dependency problem at compilation time rather than at runtime.
What are the recommended good practices for this?
Thanks!
commons-lang3 is a transitive dependency of Android App. As such, it is often not needed for compilation - there are exceptions, especially regarding multiple levels of inheritance. So at compile time you (usually) do not know whether you miss a transitive dependency that you need at runtime.
This is where Gradle comes in. Gradle can (as Maven) resolve dependencies transitively from a Maven repository (as MavenCentral). If you put MySDK into a Maven repository (like Nexus or Artifactory, which have open source versions), everyone using MySDK will automatically draw commons-lang3 so you will not miss anything at runtime.
If you are just adding the jar file in your project you can't warning about the missing dependencies.
To do it you have to publish the jar file in a maven repo.
In this way you have a pom file which describes the dependencies that gradle has to download.
Provide a method like MySDK.init() int your MySDK.jar,call a method whe is belong to org.apache.commons:commons-lang3:3.5' in the MySDK.init() method, then put init() into onCreate() of your Application,
Another way is,putorg.apache.commons:commons-lang3:3.5 into MySDK.jar,
Hope it helps you :)

Android app getting crashed : com.android.support.constraint:constraint-layout : Error

I have started to learn Android. I am trying to work on Google Map APIs. My app is crashing every time I am trying to launch it, upon investigation I found one notification in build.gradle file.
Please refer this image to see the message from compiler
I changed com.android.support.constraint:constraint-layout:1.0.0-alpha7 to com.android.support.constraint:constraint-layout:1.0.0-alpha9 to support compileSdkVersion 26. I am not finding any relevant links on Google to fix this issue.
Your compile sdk version is greater than your support libraries,
try modifying your gradle as
android {
...
compileSdkVersion 25
...
}
and within the dependency you can add
compile 'com.android.support.constraint:constraint-layout:1.0.2'
Please refer to this post, if you run the Gradle command you can see what of your dependencies has a different buildtools version.
From the post:
Run a Gradle dependency report to see what your full tree of
dependencies is. From there, you will see which one of your libraries
is asking for a different version of the Android Support libraries.
For whatever it is asking for, you can ask for it directly with the
25.2.0 version, or use Gradle's other conflict resolution approaches to arrange to get the same version.
Run:
./gradlew -q dependencies <module-name>:dependencies --configuration compile
Example:
./gradlew -q dependencies app:dependencies --configuration compile

Why won't Android Support Libraries work in my project?

Using Android Studio, I followed the steps at https://developer.android.com/tools/support-library/setup.html as acurately as I could, but it told me the following error:
Error:Could not find method compile() for arguments [com.android.support:appcompat-v7:18.0.+] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#18899229.
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
But I have already installed the Support Repository and Library! Since I also got an error saying compile doesn't belong in the dependencies block, so I changed it to classpath, and got the following, similar error:
Error:Could not find any version that matches com.android.support:appcompat-v7:18.0.+.
Required by:
:ExpenseTracker:unspecified
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
As you can see here, it still thinks the ASR isn't installed, but as the screenshot proves, it is. So what am I doing wrong here?
I think you're placing these lines in the wrong file.
They should go in the module's build.gradle file, not in the project's one (which this would seem to be, from the screenshot).
Also, the dependencies tag should not be a child of anything else. something like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
...
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-v4:18.0.+"
...
}
EDIT Did you see the comment? :)
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
My problem was that after letting Android Studio upgrade the Gradle plugin to the latest version, it had messed up the dependency section of my module's build file. It had concatenated the dependency declaration lines together (except for the lines that were mere comments). Separating the lines (placing each dependency declaration in a single line) fixed the issue.

Categories

Resources