Android Studio Google Maps API v2 - android-studio

i'm trying to use Google Maps API v2 in my project.
This is my environment:
OSX 10.9
Android Studio 0.3.2
min SKD 9 and compile SDK 14
Java 1.7.0_17
Testing on Nexus 7 4.3 with GooglePlayService 4.0.30
I get the following errors on the device. Android Studio don‘t note any errors:
11-05 07:44:33.888 2386-2386/myproject E/dalvikvm﹕ Could not find
class 'com.google.android.gms.maps.SupportMapFragment', referenced from method
myproject.activities.Maps.initMaps
11-05 07:44:34.052 2386-2386/myproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.common.GooglePlayServicesUtil
at myproject.activities.Maps.onResume(Maps.java:36)
The error point is clear: There are missing class files.
Here are the dependencies of my project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 14
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 10
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.android.support:gridlayout-v7:18.0.+'
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:support-v13:19.0.+'
compile 'com.google.android.gms:play-services:4.0.30'
}
In my opinion should be compile 'com.google.android.gms:play-services:4.0.30' enough.
So any suggestions what's missing ?
Greetz,
Moddus

I had the same problem.
When I changed the version to 'com.google.android.gms:play-services:3.1.36' my app started normally without any errors but the map was white.
Tried several diferent api keys and still don't know where the problem is...
edit: Finally I made my app to shows up the map by changing the classpath of the buildsctipt. I'm using Android Studio v.0.4 which comes with gradle:0.7 and I gess it has a problems for now with google play services. Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.android.support:appcompat-v7:+'
}

Related

Gradle Sync failed: Could not find method implementation()

Been trying to resolve this error for hours...cant get it solved. I am a newbie to Android Studio
My project level build.gradle file is as follows
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}
And my app build.gradle file is as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 18
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.amazonaws.androidtest"
minSdkVersion 8
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
aaptOptions {
cruncherEnabled = false
}
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.1'
}
}
apply plugin: 'com.google.gms.google-services'
Getting the following error when trying to sync
Gradle sync failed: Could not find method implementation() for arguments [com.google.firebase:firebase-core:16.0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I am using Android Studio 2.3
Tried to upgrade Gradle to version 4 but that requires Android Studio 3. Cant install Android Studio 3 for now.
Also added the maven url's as some answers suggested. Still not working.
Any other way to resolve this?
with build-tools 3.1.4, it should become known (read below):
classpath "com.android.tools.build:gradle:3.1.4"
but if you cannot update Android Studio , use compile instead of implementation.
compile "com.google.firebase:firebase-core:16.0.3"

Gradle cannot find symbol class in Android Studio project

Gradle has trouble resolving a dependency in an Android Studio project. I have a library that has a dependency to a java module called "common". I have the dependency speficied in the buld.gradle (see below), however, I still get "cannot find symbol MyClass" when building. How can I fix this?
The line in error is the import that references the package in "common".
Building works fine with maven, but not with gradle.
This is the build.gradle of my lib.
apply plugin: 'com.android.library'
android {
compileSdkVersion 17
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':common')
}

Gradle dependency for MPAndroidChart not working in Android Studio

Trying to install MPAndroidChart, I tried to follow the instructions in the Readme for adding the library as a gradle dependency.
EDIT:
I didn't edit the top-level build.grade file, only the build.gradle file in my app directory. The latter looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.gmail.konstantin.schubert.workload"
minSdkVersion 16
targetSdkVersion 23
versionCode 7
versionName "1.1.5"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.guava:guava:17.0'
compile 'joda-time:joda-time:2.8.2'
compile 'com.android.support:design:23.0.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
}
As you can see, I have added the maven repository and the compile instruction in the dependencies.
However, Android Studio gives me an error:
Error:(32, 13) Failed to resolve: com.github.PhilJay:MPAndroidChart:v2.2.3
EDIT: Here are the instructions as given by JitPack: https://jitpack.io/
I believe I followed them to the letter.
What am I doing wrong? What am I forgetting?
EDIT: The question is really following the wrong lead. Looking at my gradle log, I discovered the following error:
* What went wrong:
A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not resolve com.github.PhilJay:MPAndroidChart:v2.2.3.
Required by:
workload:app:unspecified
Could not GET 'https://jitpack.io/com/github/PhilJay/MPAndroidChart/v2.2.3/MPAndroidChart-v2.2.3.pom'.
> peer not authenticated
This is a much better lead to follow and can easily be googled.
please edit your top level gradle file like this:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
other thing.. take a look at gradle console in the bottom right of android studio, and show me the log.
It is a problem with java/gradle on linux not recognizing the ssl certificate. The easiest solution is to use java 8, see https://www.jitpack.io/docs/FAQ/.
I am on Debian 8.5 Jessie and using openjdk 8 (instead of the stock 7 version) from jessie/backports solved the issue (building gnucash-android) on my system.

failed to build tool version android

I tried to open an old project of mine in a freshly installed android studio (today), It gave me this error :
failed to find build tools revision 23.0.0 rc2
install build tools 23.0.0 rc2 and sync project
I looked for it in the internet and I tried to add this in the gradle file :
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
And it gave me another error:
gradle DSL method not found: 'android()'
possible causes:
the project may be using a version of gradle that does not contain the method.
gradle settings.
the build file may be missing a gradle plugin.
apply gradle plugin.
this is my gradle file :
// 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.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
Right click on your project > Open Module Settings > Properties Tab, then change :
Compile Sdk Verion to API 23: Android 6.0
Build Tools Version 23.0.0
I checked the build tools version installed in my Android Studio and I have Android SDK Build-Tools rc3, Not rc2.
I changed it in build.gradle (Module App) to
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"}
After that it works.
Check if you have the same issue.
In your top level build.gradle you have to remove the android block
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
}
Just use:
// 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.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
You have to use the android block, in the app/build.gradle where you should define something like:
apply plugin: 'com.android.application'
android {
compileSdkVersion XX
buildToolsVersion "XX.X.X"
defaultConfig {
minSdkVersion XX
targetSdkVersion XX
versionCode 1
versionName "1.0"
}
buildTypes {
release {
//......
}
}
}
dependencies {
//......
}
theres 2 gradle files
the one you have to modify is the one under this directory
APPLICATION NAME / APP / BUILD.GRADLE
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "PUT THE CODE YOU WANT HERE EX "23.0.0 r3""
defaultConfig {
applicationId "org.app.appname"
minSdkVersion 10
targetSdkVersion 22
versionCode 9
versionName "1.10.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile files('libs/volley.jar')
}
not the one which looks like these
// 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
In my case I tried everything and finally I had to do a simple change from this
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
}
to this
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0" //DELETE rc2 AND SYNC PROJECT
}
It depends on which version of Android SDK Build-tools you have installed, you could check it via the SDK Manager, in my case I haven't the 23.0.0 rc2 installed but the 23.0.1, so you need to edit your app/build.gradle
for me it was then:
android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
}

gradle error "Execution failed for task ':app:compileDebugJava' " while build groovy in android studio

I got a error while building groovy code in android studio.
the error msg is
C:\Users\Administrator\Desktop\lytest110\app\src\main\java\gzzhe\com\lytest110\MainActivity.java:41: error: can't find symbol
Log.d("lytest110", GroovyTest.getMsg());
^
symbol: parameter GroovyTest
possition: class MainActivity
1 error
FAILED
:app:compileDebugGroovy
FAILURE: Build failed with an exception.
my build.gradle is:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
the build.gradle in app directory:
apply plugin: 'com.android.application'
apply plugin: 'me.champeau.gradle.groovy-android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "gzzhe.com.lytest110"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/groovy-2.4.0-beta-3-grooid.jar')
compile files('libs/android-support-v4.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
// compile 'com.android.support:support-v4:19.+'
}
I have put the groovy file into main/groovy/package/name directory.
the groovy is annotated with #CompileStatic.
This problem have puzzled me for several days.
From your error it seems like you are calling Groovy class with Java. According to the Android Groovy plugin readme. it says
Groovy sources must be found inside src/main/groovy. Note that the plugin follows the behavior of the Groovy plugin in Gradle, which means that if you want to be able to have Groovy classes referencing Java classes that themselves reference Groovy classes, then those Java classes must be found inside src/main/groovy too (this is called joint compilation).
So you just put your MainActivity.java to your ../main/groovy/package/name directory

Resources