Android Studio - Google-Play-Services - com.google.android.gms.empty - android

I am experiencing issues with creating a project that uses google play services in Android Studio. I am able to import com.google.android.gms, but nothing else. after I hit . after gms, I get the options of importing * or R. There is no option for GoogleMap, GooglePlayServicesUtil, etc.
I have tried quite a few different things, and have scrapped the project multiple times and started from scratch. At first I attempted to import the google-play-services_lib as a module into the project, but that did nothing, and after reading for a while I found that this was the incorrect way to do it.
I have since tried this (which seems to be the correct way) but it still is not working.
Code from Gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 18
}
}
dependencies {
compile 'com.google.android.gms:play-services:3.2.65'
}
As I mentioned, I do not have any error with the compile line. In fact, 'intellisense' detects com.google.android.gms. Just nothing after that, so I can't import anything useful.
Any help would be greatly appreciated. I have been banging my head against a wall with this. It would help to have a fresh set of eyes.
Thanks!

It needs to Sync project with gradle files everytime you edit build.gradle so AndroidStudio can fetch the changes.
Note, that your build tools are outdated:
android {
buildToolsVersion "18.1.1"
}

Google Play services Integration.
Step 1:
SDK manager->Tools Update this
1.Google play services
2.Android Support Repository
Step 2:
chance in build.gradle
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.+'
}
Step 3:
android.manifest.xml
<uses-sdk
android:minSdkVersion="8" />
Step 4:
Sync project file with grandle.
wait for few minute.
Step 5:
File->Project Structure find error with red bulb images,click on go to add dependencies select your app module.
Save
Please put comment if you have require help.
Happy coding.

Related

Choosing a right version of support library base on compileSDKversion

my compileSDKversion is 26, so i want to add some support libraries into the app build.gradel such as implementation 'com.android.support:card-v7:26.x.x'.
How do i choose the right version for my current compileSDK version?
I just did "try and fail". I mean, i type x=1 then running "sync project with gradle", and wait for the IDE notifies it runs fine. But i don't know what exactly appropriate version i should use. I did search, i found some people tell the version of support library basing on compileSDKversion, and should use the last 'compileSDKVersion', but that doesn't solve my problem.
This https://developer.android.com/topic/libraries/support-library/setup can help you to setup a support librairy.
I think in your case card is cardview. Because I don't find card when I try sync.
This is an exemple of what I suggest for sdk 26
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
...
targetSdkVersion 26
...
}
...
}
dependencies {
...
implementation 'com.android.support:cardview-v7:26.1.0'
...
}

Gradle failed to sync with 'unable to find optional library'

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.

Android Studio Error:(3, 0) Plugin with id 'com.android.application' not found

I'm new to android studio and had somebody write an app I made which was originally used in app inventor. I followed his template and added new things. The app has a problem with the Gradle and gives me the following.
"Error:(3, 0) Plugin with id 'com.android.application' not found."
It also says that my extras Android Support Repository isn't installed however it is. and everything is up to date. I saw many things about updating the Gradle, How do I do that if the SDK manager didn't.
code is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
defaultConfig {
applicationId "contactorganizer.introcode.or.myapplication"
minSdkVersion 8
targetSdkVersion 21
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:appcompat-v7:21.0.0'
}
Sorry about not having much knowledge.
If you would like the project I can email it to you because I have absolutely no clue and would love to just build this.
Thanks for your help!
When I updated my Android Studio to the latest, I got the same problem. Here is how I solved it.
First:
Add the following code to the top of your build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Second: Find the gradle-wrapper.properties.
Change the last sentence to this:
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
Hope this works for you.
I have faced the problem too. The android plugin is 1.2.3. It appears when running one module task in the module directory like this way, ../graldew :module:xxx.
I eventually notice plugin 1.2.3 cannot get right context and android plugin 1.5 works well. So It will work to give it right gradle file.
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
This is the situation for me. You can just regard it as a reference.

How to add google play services in IntelliJ IDEA 13 with gradle

I want to add the google play service to my project with gradle but every time I try to build/ run I get the following error:
Gradle: A problem occurred configuring project ':BPA App'.
Could not resolve all dependencies for configuration ':BPA App:_debugCompile'.
Could not find com.google.android.gms:play-services:4.2.42.
Required by:
BPA App:BPA App:unspecified
My build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
// maven { url "http://dl.bintray.com/populov/maven" }
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.google.android.gms:play-services:4.2.+'
}
Of course I have installed google repository and other things from the SDK-Manager.
The support-v4 and support-v7 libs works fine.
I´m new in builds with gradle. Before gradle I have imported the service-lib as a module and everything works.
Hope someone can help me.
There could be several things going on here:
You don't have installed the Google Play Services extra from the SDK Manager. So you can go there and install it. (Not just Google Repository, but Google Play Services itself)
If you got the extra installed, but Studio doesn't recognize it, maybe you're pinpointing the wrong SDK. It happens that Android Studio had its own pre-bundled SDK, so, if you got another one installed on your computer, you may be installing the extras in that one, and AS is triying to build with the one that has not the extras installed.
Check it out in Files>ProjectStructure and make sure you got the right SDK.
To get play services I usually go for:
compile 'com.google.android.gms:play-services:4.2.+'
This will give you the latest variant of 4.2 (i.e. 4.2.highest available incremental version)
Move mavenCentral() to the top, dependencies are resolved in top down order, if that still fails remove maven { url "http://dl.bintray.com/populov/maven" } as a test
I know that it is not the best practice not to mention the version of the compiled code but if you do not want to update your dependency section each time you update your google play services (using SDK manager), just put this reference in your dependency section:
compile 'com.google.android.gms:play-services:+'

Android Studio Glass App cannot resolve Card symbol?

I have created a template project from minimum & target SDK 15 and compile SDK Google Glass Sneak Peek.
Ive only added this code to the MainActivity Class:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Card card = new Card(this);
card.setText("Hello World");
card.setFootnote("santiapps.com");
setContentView(card.toView());
}
but the Card words are all highlighted red saying Cannot resolve symbol Card.
I checked a StackOverflow which pointed to dependencies, but I checked my 2 build.gradle files (cause I don't know which it should be) and they have:
Innermost build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 15
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
}
Outtermost build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Where dependencies are highlighted yellow saying 'dependencies' cannot be applied to groovy.lang.closure.
Ive clicked the button to resync gradle files but it doesn't get rid of the dependencies yellow warning.
I also get a red warning under the word google:
import com.google.android.glass.app.Card;
The other thing I noticed is that in a sample hello-world I downloaded I was able to see in File->Project Structure->PlatformSettings an entry for Android SDK but in my case I only get this:
So Im not sure what else to do. Thanks in advance (Android Studio 0.4.3)
You're not declaring the glass sdk dependency anywhere.
You'd either have to copy it from your $ANDROID_HOME/add-ons/addon-google_gdk-google-15/libs/gdk.jar to your local project and then add it to your dependencies like this:
dependencies {
compile files('libs/gdk.jar')
}
or upload it to a repository and then add it to your dependency section.
This was the solution for me:
http://b2cloud.com.au/uncategorized/google-glass-gdk-setting-up-the-project
It seems Android Studio doesn't specify that it must build that project with GDK even if you specifically tell it to when creating the New Project.
The previous answers are now outdated. Please don't directly include the gdk jar file.
Make sure you update Android Studio to the latest version (at least 0.5.5) and put:
compileSdkVersion "Google Inc.:Glass Development Kit Preview:19"
in your app's build.gradle file. (For most projects, this is app/src/build.gradle.)

Categories

Resources