not able to import com.google.android.gms.iid.InstanceID into my project - android-activity

I'm not able to import com.google.android.gms.iid.InstanceID into my code is it a library problem or should i need to update the library, since instanceID is available and many have implemented using the same.

I had this issue as well, and it ended up being that I had an older version of the android sdk tools. Getting the newest version from the developer website and installing the Google Play Services library again solved the issue.

I too had the same issue. Got it resolved by compiling with the latest sdk tool versions.(Play services,build tools etc). Sample build.gradle is shown below for reference.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.abc.bcd"
minSdkVersion 14
targetSdkVersion 23
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.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.0.1'
}
enter code here

Related

Cannot add extension with name 'googleServices', as there is an extension already registered with that name. - Ionic Capacitor

I have a mobile app written using Ionic Angular. My Ionic version is 5. I build it with Capacitor.
I have added Admob Free plugin to my app and the ad implementation is working fine. Later I wanted to integrate push notifications into my app, so that I decided to go with FCM plugin.
Now when I open the android platform of the project in Android Studio, I get the below error in build console. Note that I have placed the google-services.json file in the correct place.
Cannot add extension with name 'googleServices', as there is an
extension already registered with that name.
app -> build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "my.app.id"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
url "https://dl.bintray.com/ionic-team/capacitor"
}
flatDir{
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation project(':capacitor-android')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':capacitor-cordova-android-plugins')
}
apply from: 'capacitor.build.gradle'
apply plugin: 'com.google.gms.google-services'
Project level -> build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
As I think, Admob plugin internally uses the google services plugin and when FCM plugin tries to add the same plugin this error occurs. Correct me if I am wrong.
Anyway, can someone please help me to resolve the issue.
Thank you..!

fix the error : Plugin with id 'com.android.application' not found

When I create a new project in android studio, at first every thing is o.k and it runs on my mobile phone. But if I press the sync button then a terrible error(which I afraid of and hate it) is appeared: "Plugin with id 'com.android.application' not found". I search and read all answers related to this error and do every thing. But my problem is also remained.
Here is my build.gradle(module.app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.masood.pietest"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
and here is my build.gradle(project):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha09'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Really, I don't know what I need to do...
Could anyone help me?
After 3 days of trying to solve my above problem and searching and examining very solutions, I found that the problem raised from my "Android Plugin" version. So, if this problem occurs for every one especially for those who are new to android studio, before all, try to use from an appropriate version of "Android Plugin" which adjust with "Gradle version". To do this it's enough to look at this address: https://developer.android.com/studio/releases/gradle-plugin.html#updating-plugin and https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle.
For example, my Gradle version is "gradle-4.4" which requires at least to Plugin version "gradle:3.1.0". My Plugin version (when I had the above problem was gradle:3.1.0-alpha09) and the Sync process was encountering with error. So I change it to : "gradle:3.1.0" and now it works very well.
Notice:For checking your "gradle version" please go to the below directory on your application:
Gradle Scripts -> gradle-wrapper.properties
and for "plugin version" go to: Gradle Scripts -> build.gradle(Project:...) (NOT: build.gradle(app:...))
I hope this answer be useful for every one who have the same problem.

Android Studio Emulator: App won't run unless you update google play services

I am building an application that uses the google maps api.The first activity of the application is a maps activity, which refuses to run based on the error I stated in the title.
I have heavily modified my build.gradle trying to fix the problem; based on other solutions I found on this website.
But I think I may have made it worse: This is what my build.gradle looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.navigation.dixongardens.ben.bensgardens"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:28.0.0-alpha1'
compile 'com.google.android.gms:play-services-maps:11.6.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
// androidTestImplementation 'com.android.support.test:runner:1.0.1'
// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.maps.android:android-maps-utils:+'
compile 'com.google.android.gms:play-services:11.8.+'
compile 'com.android.support:design:26.0.0-alpha1'
}
Can someone help guide me as to what is wrong with my build.gradle? I am confused as to which dependencies are required for google services to work properly.
It's not an issue with your app, but an issue with your emulator. You need to update the emulator you are running / download a new system image and create an emulator from that.
The exception is telling you that Google Maps expects a newer version of Google Play Services than what is currently running on your device. Sometimes it will have a link to update google play services under the notification. (in the app on the google map view)
You don't need to do anything, only you need to click notification showing above message. Then google play service will be updated automatically. Easy

How to include MapBox v5 with Android Gradle?

I added the dependency for MapBox com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.0-beta.3 as compile 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.0-beta.3' stated from here or here. But when i run this, I receive this error:
Error:Module 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.0-beta.3'
depends on one or more Android Libraries but is a jar.
I thought of changing it to get the #aar instead just like this:
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.0-beta.3#aar') {
transitive = true
}
I ran it and it builds fine. But when I build my app, it throws a bunch of compile errors like it cannot resolve app:style_url or any other MapView specific xml attributes.
I also tried adding MapBox directly from Android Studio to no avail.
How can I use MapBox 5.0.0-beta.3 in Android? Am I missing something? I am still using v4.2.2 and I have some issue and it seems that they have merge it with v5.0.0-beta.3 and requested to try it and so I did.
What am I missing? Can I just download the actual .aar files so I can just include it manually?
Here is gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 25
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "#############"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "0.2.33"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable "ResourceType"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
testCompile 'junit:junit:4.12'
compile 'joda-time:joda-time:2.3'
compile 'com.wang.avi:library:2.1.3'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:percent:25.2.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.code-troopers.betterpickers:library:3.0.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:multidex:1.0.1'
compile 'ca.barrenechea.header-decor:header-decor:0.2.8'
compile('com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.1#aar') {
transitive = true
}
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.2.0'
compile 'com.google.android.gms:play-services:10.2.0'
compile 'com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.2#aar'
}
Thanks!

Android Studio ActionBarActivity not working after trying to import a JAR library

I have the latest Android Studio running and I also made it to run my first app without any problem.
Then I wanted to add gson library to use in my project but I must have done something wrong because since then my ap does not work any longer since this import fails:
import android.support.v7.app.ActionBarActivity;
I have also added this now for gson in my gradle file:
dependencies {
compile 'com.google.code.gson:gson:2.3.1'
...
I did:
Invalidate cache and restart
delete my .gradle folder
But nothing works.
Do you have any idea what I might have mixed up?
Thanx for your help!!!
These are the files:
Build.gradle project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0-rc4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Build.gradle (app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "xxxxx"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.3.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:support-v4:21.0.2'
}
The error that comes is "Cannot resolve symbol 'ActionBarActivity'"
After a gradle sync it looks fine but when I then try to run my project, that ActionBarActivity s again not recognized ... but it was before...
#
Now I have deleted the .iml file and the .idea folder and re-imported my project.
It looks good but now Android Studio is unable to install the .apk on my device when I want to run it:
Failure [INSTALL_FAILED_INVALID_APK]
(so I opened a new question...)