I am trying to add a library dependency from my Android Studio for below:
'com.google.android.gms:play-services-analytics:7.5.0'
However, I couldn't find the package.I even searched for it on search.maven.org but couldn't find it.However in the google docs it is mentioned :developers.google.com/android/guides/setup Can someone point the mistake I am doing?Meanwhile I acheived my task using this link
To make the Google Play services APIs available to your app:
Open the build.gradle file inside your application module directory.
Add a new build rule under dependencies for the latest version of play-services.
apply plugin: 'com.android.application'
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.5.0'
}
Be sure you update this version number each time Google Play services is updated.
3.Save the changes and click Sync Project with Gradle Files in the toolbar.
Related
I'm trying to create a project which includes an Android library and a Java library in Android Studio (3.1). The Java library depends on the Android library. Both are modules in my project like this:
MyProject
|-android
|-java
Both appear in settings.gradle:
include ':android', ':java'
And the Java library depends on the Android library like this:
java (build.gradle):
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':android')
}
...
android (build.gradle):
apply plugin: 'com.android.library'
...
When trying to sync the project I'm getting the following error:
Failed to resolve: project::android
Why?
P.S. The other way around (Android depending on Java) works just fine.
First let's try to fix the build error. Let's run ./gradlew build --stacktrace to see a more detailed output:
Caused by: org.gradle.internal.component.AmbiguousConfigurationSelectionException:
Cannot choose between the following configurations of project :androidLibrary:
debugApiElements
releaseApiElements
AGP is confused which variant to choose. After inspecting this answer, we can find how to overcome the issue:
implementation project(path: ':androidLibrary', configuration: 'default')
After trying to sync the project with that setup you'll see following output in console:
Ignoring dependency of module 'androidLibrary' on module 'javaLibrary'. Java modules cannot depend on Android modules
Thus, seems like what you try to do is not supported by the plugin.
Refer to similar question, where Nick Cardoso tries to clarify the case.
Gradle project sync failed and did not get answers from other related questions. Here are the details of my situation.
Initial sync attempt yielded the following error message:
Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
I have Android Studio 3.0. The build.gradle file includes the following dependency:
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
The gradle-wrapper.properties file includes the following distribution URL:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
According to https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle I need to make some changes.
First, update the Gradle version for Android Studio 3.0 in gradle-wrapper.properties:
distributionUrl=\
https://services.gradle.org/distributions/gradle-4.1-all.zip
(I believe the backslash right after the equal sign is an error and did not make that change.)
Second, add the following buildscript repository to build.gradle:
google()
Third, change the build.gradle dependency:
classpath 'com.android.tools.build:gradle:3.0.1'
The second and third changes apply the latest version of the Android plug-in.
When I try to sync after these changes it fails again with the following new error:
Plugin with id 'com.android.model.application' not found.
The error refers to the first line of build.gradle:
apply plugin: 'com.android.model.application'
What is happening and why? I recently added NDK to Android Studio. The project I'm trying to sync includes C code. I'm not completely certain I added NDK correctly. I wonder if that could be part of the problem.
First, the gradle-wrapper.properties is incorrect. You must include \ in it. It should be something like this:
#Sat Jun 17 17:47:18 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Then, add the experimental classpath to project build.gradle. Something like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle-experimental:0.7.0-alpha4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Check the Experimental Plugin User Guide for details.
Go to your build.gradle version or update it
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
You should change you dependencies classpath
All steps are here :
Open build.gradle and change the gradle version to the recommended version:
classpath 'com.android.tools.build:gradle:1.3.0' to
classpath 'com.android.tools.build:gradle:2.3.2'
Hit 'Try Again'
In the messages box it'll say 'Fix Gradle Wrapper and re-import project' Click that, since the minimum gradle version is 3.3
A new error will popup and say The SDK Build Tools revision (23.0.1) is too low for project ':app'. Minimum required is 25.0.0 - Hit Update Build Tools version and sync project
A window may popup that says Android Gradle Plugin Update recommended, just update from there.
Now the project should be runnable now on any of your android virtual devices.
Make sure your Gradle version is compatible with your Android Gradle Plugin.
https://stackoverflow.com/questions/24795079
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
How can I use an application from another project as a library, when that application depends on a library that I am already using?
Here’s what I have:
MyProject
app
libraries
ExoPlayer
demo
library
Here's my current configuration as it pertains to this.
demo/build.gradle:
apply plugin: 'com.android.application'
...
dependencies {
compile project(':library')
}
library/build.gradle:
apply plugin: 'com.android.library'
MyProject/settings.gradle:
include ':libraries:ExoPlayer:library'
MyProject/app/build.gradle:
dependencies {
compile project(':libraries:ExoPlayer:library')
}
As you can see I’m using ExoPlayer library as a library (go figure) but I want to use demo application as a library as well (specifically for the DemoPlayer, I don't want the activities). But demo also has a dependency on library. What do I have to put in my gradle files to achieve this?
I tried to follow the library setup and apply it to demo but it broke the demo build:
Project with path ':library' could not be found in project ':libraries:ExoPlayer:demo'
I have tried following other similar threads such as this one but with no success.
I appreciate any help.
A long time ago I've use Exoplayer as a library project but it's not needed anymore : you can use gradle dependencies :
compile 'com.google.android.exoplayer:exoplayer:r1.4.2'
If you want to persist with library project, you will have to check your settings.gradle where all Android Studio referenced module are in. This file contain the name of module as you will use it after.
Example : (based on AndroidVuMeter)
settings.gradle
include ':app', ':vumeterlibrary'
project structure
Project/
app/
vumeterlibrary/
To use vumeterlibrary you will have to use compile project(':vumeterlibrary') in your app build.gradle
I have imported one project into Android Studio but I got the error:
Could not find com.android.support:support-v4:19.1.0.
Where could I find this file? I have imported the project using Gradle.
I have the Android Studio version 0.5.7 the last android sdk and java 1.7u55.
Just add this code to you build.gradle file
dependencies {
compile 'com.android.support:support-v4:19.+'
}
and press Tools -> Android -> Sync Project with Gradle Files
Gradle will download necessary files by himself
It does not work for me either. It works with 19.0.1
But if (I use gradle) I do this in my build.gradle:
repositories {
def androidHome = System.getenv("ANDROID_HOME")
mavenCentral()
maven {
url "$androidHome/extras/android/m2repository/"
}
}
It finds the artifact.
From the SDK Manager, delete and re-install the Android Support Library 19.1 package.
I had this same problem with morning. I found the Jar file that I needed in /<MySdkFolder>/extras/android/support/ - in there are some sub folders with the different support libraries in them, so the last part of the path depends on which one that you want to use.
I just copied this into the lib folder of the project. I'm sure there is a more technical solution but it worked for me.
Following theory works at me:
Android Studio has problems importing support-v4:19.1.+ library when it comes through a transitive dependency.
Solution Adding support-v4 as own dependency and exclude this lib where it comes transitive. then i could not more see this import issue
Right clicking on the library and select the import as library option from the context menu works for me.
Try to go
Project Structure -> Dependencies -> Add : then select -> File
dependecies
then select the proper library
This artifact is available on google maven repository. So need to add following in the build.gradle:
allprojects {
repositories {
mavenLocal()
google()
}
}
I had a similar problem. This line to build.gradle works -->
implementation 'com.android.support:support v4:28.0.0'
I have a module with some POJO classes that is marked at gradle as apply plugin: 'java' .Is there a way to reuse it at another project ? Everything i tried failed . (I dont want to copy pasta it)
I was facing the same issue recently.
This is how I resolved the code redundancy problem:
Create a new Android Studio project 'libs' and add all my APIs in a 'library' module.
In build.gradle of your library module, add code to upload the artifact to local Maven repo.
`
apply plugin: 'maven'
group = 'com.<example>'
version = '1.0'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file:///Users/<myuser>/.m2/repository")
}
}
}
`
The archive is uploaded in your maven repo as aar file.
Use this aar file in any other project as a dependency.
Hope this helps.
Here are two other questions on the same matter.
How do I add a library project to Android Studio?
How to create a library project in Android Studio and an application project that uses the library project
Personally I didn't use any of the two provided methods.
I built my project as a JAR, added it to the 'libs' folder, right clicked on it and clicked 'Add as library' and then finally added the dependency in the gradle file like so:
dependencies {
compile files('libs/MyJAR.jar')
}