Unable to resolve GCMReceiver after adding to gradle & libs [duplicate] - android

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'
}

Related

How to use Google Play Services 7.3.0 on AndroidStudio?

I've updated my Android SDK and also the PlayServices Library. Nothing seems to work right now.
The import com.google.android.*; does not exists, and I've added the 'compile' lines on the Gradle File.
Have someone experienced this? How can I solve this?
EDIT
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.code.gson:gson:2.3'
compile 'org.roboguice:roboguice:3.0.1'
compile 'com.google.android.gms:play-services:7.3.0'
}
That's the Gradle File for a Module.
If you use Android Studio and want to use the latest Google libraries via Gradle dependency, you will have to update the
You can do this via Tools -> Android -> SDK Manager -> You have to update the stuff under Extras
Also make sure that you are not using the Offline Mode of Gradle. You can find this option via (I did this on a Mac) Android Studio -> Preferences -> Gradle -> (Global Gradle Settings) Offline Work
Make sure this option is not checked.
Something which was mentioned by #CommonsWare already (and i add it just to sum up this answer) is to sync the project via the Gradle files. You can do this via the toolbar as seen here:
Or via the menu Tools > Android > Sync Project with Gradle Files
If nothing of the above is working for you, it would be really helpful if you can try to build the project via the command line or the terminal with the following command:
gradle clean build --debug
and then post the output here. It will hopefully show why it can't resolve the library.
Try Tools > Android > Sync Project with Gradle Files and see if that clears up your problem. There's a bug where Android Studio does not always warn you to do this with the yellow banner on the editor.

Android Studio project build issue

I'm having some strange issue with Android Studio recently. I'm trying to build a project after few modification in code. But the APK got installed is of old code. (I found this by debugging. When I debugged it was going to empty lines) But all my latest code are saved and it's there. I have tried the following steps which I know.
Delete the build folders of Project and Module manually > Restart Studio > Clean Project > Rebuild Project
Restart Android Studio and (I don't know why I restarted but I did that too)
Invalidate and Cache Restart
At some point I found a issue in XML related to style attribute for button which was like style:attr/buttonBarButtonStyle I later corrected to style:"?android:attr/buttonBarButtonStyle"I hope this change is correct because it don't show any more error.
And finally it doesn't give me any error in stacktrace. Project always shows BUILD SUCCESSFUL
Nothing above helped me.
EDIT 1 : I have updated my Android Support Library to 22.1.1 latest version which released a couple of days ago
EDIT 2 : I uninstalled Android Studio. Deleted Android Studio related folders in C:\Program Files\Android\Android Studio and also deleted C:\Users\MyUserName\.android & .AndroidStudio & .gradle folders. And did fresh install of Android Studio. Later I imported a same project and build it. Again it happens in same way! I have also tried running the same project in other lap and it runs without any problem. I Don't know what else I'm missing here
EDIT 3 : Updating my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
signingConfigs {
debug {
storeFile file("./debugkeystore/MyAppDebug.keystore")
}
}
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:6.1.+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
}
I just again uninstalled AndroidStudio and clear the registery and made it like a fresh install for the 3rd time and I don't know how but this time it worked! But didn't get what exactly happened!
I solved it by rebuilding the project. Go to the build tab
you should configure Run/Debug Configuration again and add to "Before launch" section "Gradle-aware Make"
that's it

error: package com.google.android.gcm does not exist - After migrating to Gradle

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'
}

project stopped being gradle project. NOT MIGRATING

This is not a migrated project.
I've made a small project in android studio 1.0.2 with all the default settings. It was working well until I encountered a weird problem. It recently just fell apart - literally, nothing works and I don't even know what to look at for the issue.
Background
I had a strange problem with v21/something.xml where graddle cmplained about syntax error (it was complaining about lack of /. I saw it looks different ten other similar lines and corrected it to look like the others, but something (gradle script creator?) chaged it back to the form with syntax error.
Problem
I've found that similar issue is related to wrong sdk version, I've tried changing minSdkVersion to 21 (from 11) and updated gradle to see red marks pretty much everywhere.
THe puzzling thing is, that when I looked into the event log I saw this:
12:28:43 AssertionError: Already disposed: Module: 'app': Already disposed: Module: 'app'
12:28:43 All files are up-to-date
12:30:55 Project Sync
The project 'Yamba' is not a Gradle-based project
More Information about migrating to Gradle
Clearly the project stopped being a grale one - What a Terrible Failure...
In the project tree, the .idea directory is red and everything within it plus local.properties
All .java files have a red mark on them.
When I try to run the project, it opens edit configuration dialog and there is no module specified.
How can I find the error source, and more importantly how to fix it? I can upload any code you need - just tell me what is relevant here, as there are too many files to put them all and keep it readable.
the build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.asteroth.yamba"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
EDIT:
I've made a new project under the same name, copied all the files over to it and it builds - something caused corruption in the actual project. I'll try to reproduce it

Android Studio: Failed to find: 'com.android.support:support-v4:19.1.0'

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

Categories

Resources