I have a library project FooLib which uses Google play service (location service). When I was using Eclipse, I have google-play-services-lib (also as a library project) in my workspace and I include it in FooLib, and everything is working fine. Now I am migrating to Android studio and I could not figure out a way to include Google play service in a library project. Here is what I have done so far:
Installed Google player service, Google Repository in the SDK manager. (I am using the latest Android studio 1.0.1)
2. Added compile 'com.google.android.gms:play-services:6.5.+' to the build.gradle file for FooLib under dependencies. Sync the gradle file. Here is my guild.gradle file
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:6.5.+'
compile files('libs/aws-android-sdk-1.5.0-core.jar')
}
The official doc (http://developer.android.com/google/play-services/setup.html) mentioned that I also need to add
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
to the manifest as a child of <application> tag. But in the manifest file for a library project, there is no <application> tag. I tried without the meta-data tag or adding a dummy <application> tag in the manifest and attached meta-data tag to it. Neither case works.
I tried both AndroidManifest files below
Or
I am still getting
Does anybody know how to add Google play service to a library project in Android studio? Much appreciated!
Related
We have multiple projects, depending on a many Android lib modules.
To avoid duplicated xml tags in the apps manifests, we put the relevant receivers, services and activities in their respective modules.
Till today, we used:
Android Studio: 2.2.1
gradle: 2.1.3
buildToolsVersion: 23.0.3
Today we've updated to:
Android Studio: 2.3
gradle: 2.3.0
buildToolsVersion: 25.0.0
Up until this update, everything worked just fine and the manifests were merged, we had conflicts and we fixed them. As of the update we've done, the manifests will not merge, at all!!
--- Update 1 ---
We've used the Merged Manifest view, and saw that it just doesn't include the manifests in the merge, the only thing it does merge from the modules manifest is the permissions, so for example, if I add a new permission to a modules manifest it would ONLY merge it and not the rest of the elements!
I guarantee there are a lot of stuff to merge!
--- Update 2 ---
It seems that everything outside the application tag it merges into the main manifest, and everything within the application tag, it doesn't.
--- Update 3 ---
Module that doesn't merge:
Gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
}
dependencies {
compile project(path: ':android-infra')
compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile project(path: ':engine-core-server')
compile project(path: ':engine-core-aneeda')
}
Manifest:
<manifest package="com.sensiya.voip.managers.gcm"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="com.google.android.c2dm.permission.KAKI"/>
<application
tools:node="replace">
<service
android:enabled="true"
android:name="com.sensiya.voip.managers.gcm.GcmIntentService"/>
<receiver android:name="com.sensiya.voip.managers.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.iamplus.onenumber.device"/>
</intent-filter>
</receiver>
</application>
</manifest>
Module that will merge:
Gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
}
dependencies {
compile project(path: ':android-infra')
compile 'com.sensiya:sense-services-client:1.24.2#aar'
compile project(path: ':engine-core-server')
compile project(path: ':engine-core-aneeda')
}
Manifest:
<manifest package="com.iamplus.android.senseServices"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
tools:node="replace">
<service
android:name="com.iamplus.senseServices.ContextualEventService"
android:enabled="true"/>
<service
android:name="com.iamplus.senseServices.Serv"
android:enabled="true"/>
<service
android:name="com.iamplus.senseServices.Serv1"
android:enabled="true"/>
</application>
</manifest>
Any suggestions?
It could be many things.Since you didn't provide code, I will guess you are using default merge behavior. For more information, see: Merge conflict heuristics
You can use Merged Manifest view to preview the results of your merged manifest and find conflict errors.
In general, merge by default should work. Then just use Merged Manifest view to see how & where you lost values during merging. Using Merge rule markers would help you to manage merge by assigning rules markers.
If there is no merge at all. so it's probably a dependency issue between modules.
Note that dependency order plays a crucial role with modules which have the same priority level, such as libraries.
--- Update 5.April.2017 ---
Here are some useful tips:
Try to update and rebuild other libs as much as you can.
Remove all dependencies and then clean project, then add them again. and
check if you import them properly. that could be done by build the project without issues.
Note that since gradle 2.2.0 assets from modules won't be accessible
in app.
Check you manifest if merge process is not disabled exciplicitly by attribute:
tools:node=”remove" or tools:node="removeAll" or in gradle( see
this Disable Manifest Merger in Android Gradle Build)
Try to create a demo with a module and track merging. and then match
outputs to your projects. This will make it clear that is not
configuration issue but Android Studio 2.3 ( so then re-install fresh
version )
--- Update(2) 5.April.2017 ---
After you had added code, I could see that you are using Attribute
tools:node="replace"
Under application element in your modules (and probably in app's manifest too). I think that is the reason why you didn't get any manifest merged from imported modules merged to your app's manifest. See tools:node="replace" under Node markers.
Replace the lower-priority element completely. That is, if there is a
matching element in the lower-priority manifest, ignore it and use
this element exactly as it appears in this manifest.
That means both modules above will never get any thing merged with manifest from:
android-infra
com.sensiya:sense-services-client:1.24.2
engine-core-server
engine-core-aneeda
So get rid of that attribute and clean and rebuild modules. then rebuild whole project.
If you are getting manifest merge conflicts you have two options.
1) find all the manifest files included in your project including the ones in libraries that you have as dependencies, and ensure there are no conflicting configurations.
or 2) add some merge resolution rules to your Manifests to dictate how each conflict should be resolved.
There is a great page on that here with many details.
https://developer.android.com/studio/build/manifest-merge.html
From Android Studio
Build ---> Clean project
then
Build --> Make Project
This should help fix
I had a similar problem for Unity. I was able to solve it by going on the SDK Manager and removing the latest android api. Then I installed a slightly older api and it worked (API 21 or 22 I think)
What the SDK Manager looks like
I recently have same problem in my production code.
Having one libraries into app module exists also in other Gradle Dependency causes the duplicate entries.
We need to exclude such module or libraries from conflicted one.
For that we must know number of libraries used by a particular Gadle dependency.
Consider a case where I using "bolts-android-1.2.0.jar" in my app gradle.
In same gradle I m using facebookSDK as below.
compile('com.facebook.android:facebook-android-sdk:4.5.0')
So I have to exclude "bolts-android" as below
compile('com.facebook.android:facebook-android-sdk:4.5.0') {
exclude module: 'bolts-android'
}
So how to know that facebookSDK uses "bolts-android"
Here you can use plugin Android Method Count
Seems like the problem is from using tools:node="replace" in the application element. From the documentation:
...if there is a matching element in the lower-priority manifest, ignore it and use this element exactly as it appears in this manifest.
What you actually want to use is tools:node="merge" which is the default behavior.
Merge all attributes in this tag and all nested elements when there are no conflicts using the merge conflict heuristics. This is the default behavior for elements.
I have a problem with an old project which was developed in IntelliJ without Gradle. I wanted to migrate it to Android Studio and Gradle, but I am experiencing a lot of problems. Since the project was quite old, the old Google Play Services version was used. In Intellij I had just added libproject of the old gps to dependencies (google_play_services_5089000_r19) and everything worked fine. In Android Studio I managed to add other libraries by adding it as a library module and adding compile project(':segmentedradios') as a gradle dependency, but I just can't make gps library work. I've tried to add it as a module, but Android Studio says that "no module selected" after pointing to libroject library's directory. I also tried to add it as a gradle dependency, but I am keep getting errors like these:
error: package com.google.android.gcm does not exist
error: package com.google.android.maps does not exist
error: cannot find symbol variable GCMRegistrar
Despite I tried ~10 different solutions, the project still does not work. How to fix it?
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion "Google Inc.:Google APIs:18"
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "my_package.app_name"
minSdkVersion 14
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/libGoogleAnalyticsV2.jar')
compile project(':segmentedradios')
compile 'com.google.android.gms:play-services:5.0.89'
}
GCMRegistrar is not part of Google Play Services, but is part of the now entirely deprecated gcm.jar file.
You'll need to add gcm.jar to your dependencies if you'd like to temporarily keep using it until you migrate to Google Play Services' GCM implementation:
compile files('libs/gcm.jar')
You can download gcm.jar by this path
http://www.java2s.com/Code/Jar/g/Downloadgcmjar.htm
or this
http://www.java2s.com/Code/JarDownload/gcm/gcm.jar.zip
After you download it, unzip it, it should have extention .jar not .jar.zip
Then copy and paste it to libs dir in your project
Then right click on gcm.jar and click on add as lib
That is it
You need to add these both lines in your build.gradle file of your application :
dependencies {
...
compile 'com.google.maps:google-maps-services:0.1.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
I am doing a project on Beaglebone Black and i have ported Android KitKat on it. Now i need an android app that could help me access those gpios on beaglebone for a project.
So i am using android studio 1.3.1 to create my application for my project and so to access the hardware pins via android i have to use NDK for it. Now when i am trying to sync gradle 2.2.1 with my NDK files it prints an error that i should set android.useDeprecatedNdk=true. Now when i do that it again shows the error that DeprecatedNdk() is not defined.
Although i have downloaded the latest version of NDK i.e. android-ndk-r10e from android developers website but the error still persists.
Following is the build.gradle file from the module.
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.packt.gpio"
minSdkVersion 19
targetSdkVersion 19
ndk {
moduleName "packtHAL"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.+'
}
Also the error that it is showing is:
Error:(14, 0) Error: NDK integration is deprecated in the current plugin.
Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.
And if i add the property to the file then it shows the following error:
Error:(6, 0) Gradle DSL method not found: 'useDeprecatedNdk()'
Possible causes:The project 'gpio' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
If anyone has any idea as to what should be done regarding this. Please share your ideas.
Thank you
Please check the new documentation: http://tools.android.com/tech-docs/android-ndk-preview
Here are the latest project setup instructions: http://tools.android.com/tech-docs/new-build-system/gradle-experimental
This just popped up too: http://ph0b.com/new-android-studio-ndk-support/
I have a problem with an old project which was developed in IntelliJ without Gradle. I wanted to migrate it to Android Studio and Gradle, but I am experiencing a lot of problems. Since the project was quite old, the old Google Play Services version was used. In Intellij I had just added libproject of the old gps to dependencies (google_play_services_5089000_r19) and everything worked fine. In Android Studio I managed to add other libraries by adding it as a library module and adding compile project(':segmentedradios') as a gradle dependency, but I just can't make gps library work. I've tried to add it as a module, but Android Studio says that "no module selected" after pointing to libroject library's directory. I also tried to add it as a gradle dependency, but I am keep getting errors like these:
error: package com.google.android.gcm does not exist
error: package com.google.android.maps does not exist
error: cannot find symbol variable GCMRegistrar
Despite I tried ~10 different solutions, the project still does not work. How to fix it?
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion "Google Inc.:Google APIs:18"
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "my_package.app_name"
minSdkVersion 14
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/libGoogleAnalyticsV2.jar')
compile project(':segmentedradios')
compile 'com.google.android.gms:play-services:5.0.89'
}
GCMRegistrar is not part of Google Play Services, but is part of the now entirely deprecated gcm.jar file.
You'll need to add gcm.jar to your dependencies if you'd like to temporarily keep using it until you migrate to Google Play Services' GCM implementation:
compile files('libs/gcm.jar')
You can download gcm.jar by this path
http://www.java2s.com/Code/Jar/g/Downloadgcmjar.htm
or this
http://www.java2s.com/Code/JarDownload/gcm/gcm.jar.zip
After you download it, unzip it, it should have extention .jar not .jar.zip
Then copy and paste it to libs dir in your project
Then right click on gcm.jar and click on add as lib
That is it
You need to add these both lines in your build.gradle file of your application :
dependencies {
...
compile 'com.google.maps:google-maps-services:0.1.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
I want to build an app in Android Studio with the support library but I get the following error when adding the dependency for the support library:
Error:Failed to find: com.android.support:support-v4:19.1.0
Here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '20'
defaultConfig {
applicationId "sample.myapplication"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.0'
}
I have downloaded the support library via the sdk manager.
Ok, found the problem. The Android support repository was missing. After installing and restarting Android Studio it worked.
If you are using Android Studio, then as an addition to changing the build.gradle file manually, you can also lookup the dependency via the library dependencies under the Project Structure menu item.
Double clicking that dependency will generate this line in build.gradle:
dependencies {
compile 'com.android.support:support-v13:+'
}
And also, if you are wondering what this library is about, it's described at the developer pages at developer.android.com; Support Library.
My Android Studio version is 1.1. I select tools->Android->SDK Manager, check the Android Support Library then click Install packages, solved this issue.
In my case the solution was as simple as running Build:Make Project. No amount of gradle syncing or clearing caches would do it. Of course, that required getting my project into a state where it would build successfully.
In my case I needed to add Google Maven repository.
It shows as part of the error in Android Studio and only needed to click on it to add itself.
Then Gradle built the project on its own.
Following the instruction here helped me. For whatever reason when I had to reinstall the latest version of android studio the initial download of the extras section android support library failed. I simply retried it. Followed the steps mentioned and verified it was added to the build.gradle file and did a rebuild project and good to go.
http://developer.android.com/tools/support-library/setup.html