I'm developing an App in Android studio. And I want use a Google maps API, but I can't use UI to configure project settings. I tried some different instruction to add maps, but it didn't work. I have to modify somehow build.gradle file? Can you tell me how? Does someone have experience with that?
Thanks for every advice.
If you are on 0.2 it means that you already have Google Repository and Android Repository installed(from Android SDK: terminal$ android sdk).
One of them, has the Google Play services.
Here is a full build.gradle for your module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
Notice how(easily) the play services can be included.
Also gradle version is 0.5.+ so it can be auto updated!
Also another VERY important thing, that wasted me a lot of time is the minimum sdk version!
It must be 8 or above, since google play services aren't supported for lower versions!
Related
I am trying to sync my project with the Gradle files but every time I do it I get the same error message:
WARNING: The specified Android SDK Build Tools version (27.0.0) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
My target SDK version is API 24 since I am developing an app for an Android 7.0 (Nougat) operating system.
I looked over the Android Developers site: https://developer.android.com/ and I can't find anything about what Android Gradle Plugin corresponds with which target SDK version. I've read several Stack Overflow questions where people asked about which specific Android Gradle Plugin they need for their project but none of the questions were about where to go to find that information.
Can anyone tell me how to know which Android Gradle plugin version I need?
Here are the two build.gradle files in my app folder:
(Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '27.0.0'
defaultConfig {
applicationId "com.android.example.favoritetoys"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
debuggable true
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
}
(Project)
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
}
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Since AGP (Android Gradle Plugin) version 3.0.0, there is a minimum version requirement for the Android Build Tools version, which is a designed behaviour.
See
http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.AppExtension.html#com.android.build.gradle.AppExtension:buildToolsVersion
So, if you want to force your project to use an older version of build tools, i am afraid that you need to downgrade your AGP to a version below 3.0.0.
But, question for you is why do have to use the older build tools?
As seen from https://developer.android.com/studio/releases/build-tools.
You should always keep your Build Tools component updated by
downloading the latest version using the Android SDK Manager.
For your cross reference about the differences among the three different version configurations in build.gradle, i.e. compileSdkVersion, targetSdkVersion and minSdkVersion.
What is the difference between compileSdkVersion and targetSdkVersion?
What is the difference between min SDK version/target SDK version vs. compile SDK version?
For your case, maybe you only need to change your targetSdkVersion to 28.
The Android Studio 3.1 layout preview fails to find style 'coordinatorLayoutStyle' in the current theme.
Failed to instantiated one or more classes.
Exception shown are :-
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
This happened due to use of alpha version SDK 28
We need to change the android { ... } in "build.gradle" in app file
compileSdkVersion 28 to compileSdkVersion 27
targetSdkVersion 28 to targetSdkVersion 27
Also, try to change implementations like
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' to
implementation 'com.android.support:appcompat-v7:27.1.1'
Hope this works!
For Android Studio v3.1.*, in addition we need change:
implementation 'com.android.support:design:28.0.0-alpha3' to
implementation 'com.android.support:design:27.1.1'
you can fix this issue by adding this script to the app module build.gradle, in the android section
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "27.+"
}
}
}
}
This appears to be a bug in the current version of Android Studio (3.1.3) as I was encountering the same thing. I downloaded the beta build from here and opened my existing project and the errors disappeared.
https://developer.android.com/studio/preview/?utm_source=android-studio
Not exactly a fix but hopefully it will get you back up and running.
Update
1. com.android.support:appcompat stable version 28.0.0 is released. So no need to downgrade version. Just use 28.0.0.
def supportVersion = "28.0.0"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
You can ignore design library if you don't need it.
2: You also need to update your compileSdkVersion & targetSdkVersion to remove some gradle warnings.
compileSdkVersion 28
targetSdkVersion 28
Never use alpha versions of any library, because alpha, beta and rc
versions may have bugs. And you don't want to face these types of errors often.
Important Suggestion
I suggest you migrate to androidx because android will not update support library after 28.0.0, all updates will be available to androidx package only. Check related answer.
This is fixed in Android Studio 3.2.
Go to app/res/styles and change the Theme.AppCompat.Light.DarkActionBar for this one Base.Theme.AppCompat.Light.DarkActionBar
I am trying to run an app that has a Google Maps Activity on my phone. My phone's running on Android 4.1.3 and the Minimum SDK for my project is API 15: Android 4.0.3
I just created the project on Android Studio and tried to run it on my phone. But it won't run and I am keep getting this error. Can someone tell me how to solve this?
That error probably means that you are using too much libraries. And because you are trying to use google maps I'm guessing you included everything google.
Try to just use the libraries you need.
For maps use this:
dependencies {
com.google.android.gms:play-services-maps:9.2.1
}
Reading material:
https://developers.google.com/android/guides/setup
You need to configure your gradle for multidex.
Modify the module-level build.gradle file configuration to include the support library and enable multidex output, as shown in the following code snippet:
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
See more on same link which you are refering : https://developer.android.com/studio/build/multidex.html#mdex-gradle
You can also see some related question for same error:
How to enable multidexing with the new Android Multidex support library
Android java.exe finished with non-zero exit value 1
I have this problem with my emulator, i'm using API 5.1.1 and i have the lastest version of Google Play Services from SDK Manager.
AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
In the build.grable:
compile 'com.google.android.gms:play-services:+'
Navigate to settings--> apps in your emulator and then find Google Play Services, check the version number and use it in you build.gradle
Hope this helps
Change the SDK in your emulator to v21 or lower. Physical devices are not effected by this issue.
The reason Android is complaining about an update for Google Play services is related to a known issue in Android emulators for API v22 and up (at this time 23). https://code.google.com/p/android/issues/detail?id=176348
You should try to use the latest version of Play Services in your build script as users are generally forced to have the latest version of this on their device.
This problem occurred when I start my application on emulator Android 5.1.1 (x86_64) - API 22. I have read some discussions about it, but no one from them helped me.
I tried to adjust version of Google Play Services in gradle build script (I mean you should update the script with "app" name). Don't forget to sync gradle when you update something in your script.
My gradle script "app" after updates:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.itmm.map"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services:9.0.0'
testCompile 'junit:junit:4.12'
}
Please, have a look into dependencies section. You're interesting in the follwoing line of script:
compile 'com.google.android.gms:play-services:9.0.0'
Currently, ver. 9.0.0 helps me and everything is ok. I can see MapActivity on Android emulator. 9.0.0 is not a newest version of Google Play Services (the newest is 9.6.1), but it works and it can solve your problem, if you aren't interestion in new features of ver. 9.6.1.
I had the same issue. But I followed the following things
1) First download the latest build tools and play services in Android SDK
Android Studio -> Tools -> Android -> SDK Manager -> SDK Tools -> Android SDK Build Tools -> Install them
& install Play Services by following same steps
2) Create a new emaulator with latest api level for ex( API level : 28)
3) Run the app in the latest emulator
It will work fine.
I downgraded the SDK from 5.1 to 5.0 and it's working.
Your build.gradle has this line:
compile 'com.google.android.gms:play-services:+'
This means that android will use the latest version of Google Play Services when ever the app is run. The emulator might not have all the latest updates so the app will not run. Updating Google Play Services will help.
My issue was resolved after logging in with an google account on the emulator. The 'update' button worked after that
Encountered the same problem on Android Studio 2.2. What I did was to go to SDK Manger -> Launch Standalone SDK Manager, uninstalled Broken Intel x86 Atom google_apis. Restarted Android Studio and ran the project, a popup asked Download System Image, hit OK to continue, the problem then went away.
Since I haven't seen any working solutions in 2020. There are two ways to fix this:
Easy way is to create a new emulator with PlayStore Enabled. Check before downloading system image for the emulator.
Hard way is to to install Google Play Store on the emulator manually and make the update button work. You can refer to the installation part here.
After that, the app will automatically update the Google Play Services in a few minutes. That's all.
Note: If that doesn't work, Go to Chrome -> Search for Google Play Services and open the playStore link of that app and update it there.
Check in your SDK settings if youve installed google play services:
Android Studio--System Settings--Android SDK--SDK Tools:
Look for:Google Play Services and Google Play Licensing Library and make sure that both their status is:Installed.....if the above checklist is perfect,the next step you ought to perform is:
Open your build.gradle project level gradle and check that your gradle has:
classpath 'com.google.gms:google-services:3.1.0'
Then in your App level gradle:
Under dependencies:
dependencies{
implementation 'com.google.android.gms:play-services-auth:11.8.0'
and at the end of your gradle file:
repositories {
mavenCentral()
apply plugin: 'com.google.gms.google-services'
}
Next
Click on the notification error you keep getting in your notification bar of your emulator and sign in with your google account(existing Email Address and password)
Then try and run the app again...if you still get the error,click the notification error and try to sign in,,,keep trying until eventually the google playstore app will install and prompt you to update it.
This is the simplest process,it requires a little bit of patience but evetually it works.
Good Luck
my emulator's Google Play services version is 12.6.85
so I changed the build.gradle like:
implementation 'com.google.android.gms:play-services-maps:12.0.1'
Notes:
to check emulator's Google Play services version: go to Emulator \ Settings \ Apps \ GooglePlay services
to see available versions for the build.gradle check https://developers.google.com/android/guides/releases
This issue has been incredibly frustrating for me for the past two weeks.
Using the Android SDK Manager, I updated the following:
Tools:
Android SDK Tools rev. 24.3.3
Android SDK Platform-tools rev. 22
Android SDK Build-tools rev. 22.0.1
Android 5.1.1 (API 22):
SDK Platform rev. 2
Google APIs rev. 1
Sources for Android SDK rev. 1
Extras:
Android Support Repository rev. 16
Android Support Library rev. 22.2.1
Google Repository rev.22
This is the exact list of all the repositories that I've installed and updated to with the Android SDK Manager.
However, when I attempt to add the line:
compile 'com.android.support:design:22.2.0'
Gradle becomes stuck on addDependecies. Furthermore, when I go to Module Settings, and then to Dependencies, when I try to add a new library, the 'com.android.support:design:22.2.0' does not appear within the list!
Here's additional information about my target, compile, and minimum SDK version:
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.myandroidapplication.newtestapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
What could I possibly be missing at this point? Thank you!
You have to use version 22.2.1 as it has installed on your computer.
compile 'com.android.support:design:22.2.1'
For me, I was initially adding the support library dependency by typing it out in the build.gradle of my app directly.
I cleaned the line that I had typed and added the dependency through the android studio GUI,
Go to File
Choose Project Structure
Click on the Dependencies tab
Click on the + symbol in the upper right conner and choose Library Dependency.
Search for and add the support library in the dialog that appears
Gradle build/sync should start automatically.
Don't know why, but it works for me at least.