I want to add admob to my project and have followed the instructions from the documentation but I'm getting an error:
Cannot find symbol '#integer/google_play_services_version
inside the AndroidManifest.xml. I've looked inside the sdk directory and google_play_services version 4.0.30 is installed. Here's my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/libGoogleAnalyticsServices.jar')
compile 'com.google.android.gms:play-services:4.0.30'
}
After adding it, I've synced the project with gradle. I also have the required entry in AndroidManifest.xml which gives me the error
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
The official docs say that for android studio we don't need to include the library but I don't understand why it doesn't find it.
Edit: I finally solved it. The problem was that I was using the wrong sdk. Android studio ships with its own SDK and that was set as default in the IDE.
To fix
Change your project's SDK from android-studio\\sdk to android-sdk. If you don't know how, here's how.
If you get an error about build tools not found make sure the version in your build.gradle corresponds to your new sdk's version.
You must have Google Repository installed in order to use Google Play Services in Android Studio.
If not Installed it from SDK Manager > Extras.
After Installation your library should be located on path
$SDK_DIR\extras\google\m2repository\com\google\android\gms\play-services
Related
I had to reinstall my system and today I get this error in Android Studio when I try to sync with gradle:
Warning: Unable to find optional library: org.apache.http.legacy
My project gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And my module gradle:
apply plugin: 'android'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}
From the google docs:
To continue using the Apache HTTP APIs, you must first declare the
following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
I tried the suggestions mention in this thread but they don't work. Same result with android studio 1.5 and 2 preview.
How can I fix this?
Edit: Things I've tried so far:
Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.
Change the compileSdkVersion and targetSdkVersion to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.
Top level build.gradle - /build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
Module specific build.gradle - /app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
Add org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional folder to app/libs directory and sync your project
After a lot of working this solutions work for me
.
** Studio\Android\sdk\platforms** here delete your android-23 and from sdk manager update api 23 again.**
.
it will solve your issue.
In my case, it didn't work because I was missing optional.json in <sdk-path>\platforms\android-23\optional\, directory with the following content:
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
Creating a new JSON file with with above content solved the problem for me.
You need to add org.apache.http.legacy.jar jar file in your Android Stuido project's app/libs folder.
Jar Location - `<SDK LOCATION>\android-sdk\platforms\android-23\optional`
To do this, just right click on your project and select Show in Explorer then go to ...\app\libs and paste above jar file and Sync your Project with Gradle File
Module:app
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "<ur_app_id>"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Update your project gradle file to use gradle version 1.3.1.
classpath 'com.android.tools.build:gradle:1.3.1'
Also try adding codehause repo.
repositories {
mavenCentral()
maven{
url 'http://repository.codehaus.org'
}
}
In my case the problem was actually occurring because I didn't have the correct SDK installed on that computer. Navigating to .../Android/Sdk/platforms/android-23 I could see that folder was empty. Adding SDK 23 via the SDK manager fixed the problem and allowed me to compile.
You should manually check that you have the same version of the SDK installed that is specified under compileSdkVersion in your build.gradle file.
To save time 2 solutions are best and works for me.
Solution 1 :
open your android sdk manager and reinstall API 23 (remove and install again).
Solution 2 :
Download this file which contain optional.json file
extract and move optional.json to :
C:\Users\\AppData\Local\Android\sdk\platforms\android-23\optional
if above solution is not work then try this way
I experienced this problem recently, and it is caused by the path length restriction I think it´s 256 characters maximum.
Relocate your Project and the build will succeed.
Copy "sdk\platforms\android-23\optional\org.apache.http.legacy.jar" to your app module libs directory, then add as library;
If you enable the proguard, please edit "proguard-rules.pro" to keep related classes or exception will occurred.
I heard of something about Data Binding early today. Since I wanted to have a try of it and know about it, I created a test project.
Data Binding is is a support repository available on API 7+. with dataBinder, we are capable of saying goodbye to findViewById (which is complained about a lot by developers) when binding application logics and layouts.
Here are information about my project:
Android Studio:
Current version: Android Studio 1.3
Build number: AI-141.2071668
Android SDK Tools: 24.3.3
Android Platform Version: MNC revision 2
Project build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0-beta4'
classpath 'com.android.databinding:dataBinder:1.0-rc0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Module build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
android {
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "me.danielpan.databindingsample"
minSdkVersion 9
targetSdkVersion 'MNC'
versionCode 1
versionName '1.0.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
}
And when I run this project on a Genymotion Emulator(which is Nexus 5 in Android 5.1.0), errors happened:
Installing me.danielpan.databindingsample
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/me.danielpan.databindingsample"
pkg: /data/local/tmp/me.danielpan.databindingsample
Failure [INSTALL_FAILED_OLDER_SDK]
DEVICE SHELL COMMAND: pm uninstall me.danielpan.databindingsample
DELETE_FAILED_INTERNAL_ERROR
So, I have some questions:
1, DELETE_FAILED_INTERNAL_ERROR happened many times. It seems that this error happens when I set
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
So, it's the problem of Android Build Tools of this version?
2, I followed Data Binding Guide, but I think it's old. Because Gradle Plugin has been 1.3.0-beta4, version of dataBinder should have evolved since released. So, what's is the latest version of Data Binding Plugin?
Any tips will be appreciated. Thanks in advance.
P.S.:
When I set version of Gradle Plugin 1.2.3, buildToolsVersion "22.0.1" compileSdkVersion 22, and targetSdkVersion 22, DELETE_FAILED_INTERNAL_ERROR doesn't happen again, Could somebody tell me why?
I can answer the second question. RC1 was just released, though the documentation has not been updated yet. It will read:
dependencies {
classpath "com.android.tools.build:gradle:1.3.0-beta4"
classpath "com.android.databinding:dataBinder:1.0-rc1"
}
I want to build an Android App with AndroidAnnotations.
Here is a simplified version on GitHub which fails to build/pre-process: https://github.com/aiQon/androidannotationsexample
The app is composed of a main app module and a library module.
Both use AndroidAnnotations (AA). The lib module has a workaround to find the AndroidManifest.xml in debug builds (it refers to the release manifest, because gradle does not build the debug variant for libs).
However, the manifest is found for the library module but not for the main app.
The gradle file of the main app is:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "de.stelle_beratung.androidannotationslibraryexample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apt {
arguments {
androidManifestFile variant.outputs.processResources.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
}
dependencies {
compile project(":mylibrary")
apt "org.androidannotations:androidannotations:3.2+"
compile 'org.androidannotations:androidannotations-api:3.2+'
}
Gradle complains with:
http://pastebin.com/QZtnHcZD
Could someone please point me in the right direction on how to build this simplified project to have a controller Bean in the lib module and reference it successfully in the main app activity by using AA?
I appreciate any help.
Since android gradle plugin 14.4, the following line does not work anymore:
variant.outputs.processResources.manifestFile orvariant.processResources.manifestFile
You have to use this one instead:
variant.outputs[0].processResources.manifestFile
Please note if you have multiple outputs (when using splits), you may want to use another output (other index than zero).
Ok I got it. Was using Android Studio from the Canary Channel. Going back to Beta solved the issue because I could use android gradle plugin 0.12.2. This solved everything.
I have two Android Studio projects using Google Maps. One works fine, the other is unable to find com.google.android and so can't compile. Fails with
error: package com.google.android.gms.maps.model does not exist
Both have the same code in Manifest.xml
<meta-data
android:name="com.google.android.gms.version"
android:value="4323000" />
Both have the same import statement.
build.gradle is:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.android.support:appcompat-v7:+'
}
I've read several similar questions on StackOverflow but those answers have no beneficial effect.
Any thoughts appreciated ...
Please add Google Play services to your project..
Google Play Services Rev 16 was added via SDK Manager, but it seems you have to manually add it via Project/Structure as a Dependency also. (You didn't do that on the project that was working already, but it does show up there, so somehow it added automatically in that case) So kindly add that manually..
Add this to dependencies:
compile 'com.google.android.gms:play-services:4.3.23'
And replace (or leave) 4.3.23 with version you need, i.e. 4.3.+
I install the Android Studio and build a new project, but the automatic generated code show lots of "cannot resolve" errors like "cannot resolve symbol app" in the code "import android.support.v7.app.ActionBarActivity;"
The onCreate and setContentView Method cannot be resolved too
My Android Studio version is 0.4.2 , gradle version is 1.9
my build gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
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:+'
}
You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
Well that worked for me.
Open your SDK Manager (you can find it in toolbar), and download
Android Support Repository and Android Support Library (you can find them in extras).
Google Repository and Google Play Service
Then sync your project with your gradle files (there is a button in toolbar).