Android Studio Maps Api v2 - android

My code works perfectly on eclipse. I have created a new project on Android Studio and added my classes, I have also followed this popular tutorial answer How can I create an Android application in Android Studio that uses the Google Maps Api v2?
Now the code doesn't show any red flags and it detects the imports fine but when I build the project I get these errors:
Gradle: package com.google.android.gms.maps does not exist
Gradle: package com.google.android.gms.maps.model does not exist
On a side note I have attempted to import the MAPS sample project like the tutorial says and that has worked fine but I do not know why my new project gives me these errors even though I have followed the tutorial to the letter.
Any idea guys?

If you created a new project (which uses Gradle) and then followed the tutorial, it's completely wrong.
When using Gradle (which new projects do by default), you cannot use the UI to add dependencies. You need to add them manually in build.gradle.
It's a crappy solution right now and we're working to make this better.

In short words:
Run Android Studio
Create new project
Create new module of Android Library type, remember to set the package name to com.google.android.gms
Copy res, src folders and AndroidManifest.xml file from google-play-services_lib (you can find it in your SDK folder if you installed it using SDK Manager) to the appropriate folder in your library module ([Project]/[Library]/src/main)
Remove android-support-v4.jar from libs folder under your library module, live only google-play-services.jar and google-play-services.jar.properties files there.
Make sure your build.gradle file in library module contains following:
dependencies {
compile files('libs/google-play-services.jar')
}
Make sure your build.gradle for application module contains following:
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':[LibraryModuleName]')
}
Make sure your settings.gradle contain following:
include ':MapStudio', ':[LibraryModuleName]'
You can grab layout and manifest settings from Google Maps API v2 tutorial
Keep in mind that android-support-v4.jar is neccessary only when you want to support Android v2
You can find more detailed description on my blog.

I have tried and failed many a tutorial on this, but finally find a simple solution that seem to work.
I just installed Android Studio 0.2.3 on my mac, and these are the steps that made me view a maps fragment on a fresh hello world project template:
1) Click the SDK manager button in the toolbar in Android Studio.
2) Under 'Extras' locate 'Google play services' and install it.
3) in your build.gradle file in your src directory, add this line to dependencies:
compile 'com.google.android.gms:play-services:3.1.36'
4) order and install your API-key following this tutorial: https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key
5) add the fragment to your layout xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
6) you should now be able to run your project on your device.

For those of you completely confused by everything going on with implementation of external libraries to gradle projects i have the easiest and most reliable solution.
Step by Step Guide: http://aetherstudios.net/pages/gradle.html
this might be a bit of work but it is the most reliable way i have found to get it done.

Related

Why does the Facebook Android SDK downloaded and included via jar show up as an unresolved reference in Android Studio

I was unable to include the Facebook Android SDK in the normal way so I downloaded a jar and added it to Android Studio. For some strange reason I get an error Unresolved reference: FacebookSdk even though I can see the class in the Project view:
If I am doing the wrong thing can somebody please give a lucid explanation of how to download and use the Facebook SDK in Android Studio 3.
Edit
I need to use the Facebook SDK in my app and I need to download it and add it 'offline'.
this is the sources package (as it's filename may hint for), which is for reference only. you should possibly add a dependency to the build.gradle instead; it's from the mavenCentral() repository, you can also find the artifacts here ...and a whole lot of other Facebook SDKs here.
dependencies {
implementation "com.facebook.android:facebook-android-sdk:4.36.0"
}
and also move those sources outside of the libs directory
(they still can be linked together with the fetched library).

Being to foolish to correctly implement a module library into my project

I recently started developing my really first Android Project using Android Studio 3.1.2.
Therefore I implemented a module library into my app, by cloning it from github, imported it as module library and added a dependency via right-click on app > module settings, switch to dependency tab, hit the +, select imported_module.
Additionally I checked my build.gradle(Module:app), if the dependency has been added correctly, there this line appeared:
dependencies {
...
implementation project(':imported_module')
}
Also in the settings.gradle file it says:
include ':app', ':imported_module'
Now if I want to access features of imported_module any of them can't be resolved. I browsed the official and the common forums for hours to find the one step I obviously missed but wasn't smart enough to find the solution.
Synching the project with gradle files didn't cause any visible effects
What do I still have to do to be able to use all the fancy stuff fro imported_module inside my app? Do I have to import it in a certain way?
Or do I have to modify my AndroidManifest of my app somehow? Thanks in forward!
EDIT: could it be that my app and imported_module obviously have different package names? The Project File Tree says com.domain.example.my_app for the app and com.domain.example.imported_module for imported_module. Do I have to squeeze the one into the other?
It could have been much easier, if you had mentioned what exactly you want to access in main app. May be access specifier of the member in your imported_module is private.
I kinda worked around the whole thing, by just adding a remote dependency in my build.gradle file of a new project, pasted my java classes and my res into this new project, synched it and now it runs. Nevertheless thanks for thy help!
That should be really all. Be sure to sync your project with Gradle files (File - Sync Project with Gradle Files).

Where's gradle-installed library's source located?

In an android project, when you install library with gradle
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
Is there a way to look at the source of the library?
edit
https://developers.facebook.com/docs/android/getting-started
Talks about the sample code is included in the sdk. How do I view this sample source?
You can see the source code and the samples of Facebook Android SDK on GitHub:
https://github.com/facebook/facebook-android-sdk/
https://github.com/facebook/facebook-android-sdk/tree/master/samples
you can to initialize FB sdk 4.0 in sattings.gradle file
include ':app', 'FacebookSdk'
it will load whole SDK.
but still it gives you just iml file. it just pulls everything dynamically when called.
----------- Edit ----
I just tried rightnow,
If you are using android studio,
Just select your project explorer, as Project. generally its Android.
it that you will see whole list.
I can see facebook folder with all of its classes.
Let me know if it works for you.
Here in my project i have initialized FB SDK 4.0.

How to Use Android PagerSlidingTabStrip library or any other gradle built library in Eclipse

I have a problem importing the PagerSlidingTabStrip library into Eclipse, I get multiple errors and I know this happens because the library was built using gradle.
I tried to follow this answer but I can't find use as source folder in the build path menu.
I've never used gradle previously and don't know how to go about this in Eclipse. Please guys, help most of us who have this problem out of our dilemma. Would be very grateful.
Okay in the end this was what i did:
I checked the build.gradle file of the library for target and min sdks. I then put what i found in the android manifest.xml which I know Eclipse uses.
I deleted the build.gradle and gradle.properties files.
Made sure the project was marked as a library. And it works!
I think the most crucial step was to check the build.gradle for the sdks and whatever else the project requires and replicating that the way it should be in the manifest file.

How do I import com.google.android.gms.* in Android Studio using a Gradle build?

I have followed the procedure as described here : Setup
I have clicked on the little 'Sync project with Gradle' button. Gradle and Android Studio seem to find everything but then I can't actually use the gms code. If I try to import, I will get autocomplete for com.google.android.gms but no further. I have updated all the packages with Android SDK Manager.
I'm running Android Studio 0.4.2.
My minSdk is set to 9
my build.gradle includes compile 'com.google.android.gms:play-services:4.0.30'
As far as the procedure is concerned I should be ready to code, but it just doesn't work. Any ideas?
[Edit, added info]
I can find the ComGoogleAndroiddGmsPlayServices3265.aar file in my exploded bundles directory. Inside of that file I also find the common directory and inside that I find the GooglePlayServicesUtil.class (which is what's not being found in my app)
I am lost.
[Edit 2]
The problem is not specific to Google Play Services OR Android Studio. I tried adding another library (HoloColorPicker) and had the same results. However, I was able to add the library's resources to my project! I was able to add them in my XML layouts and view them in my application. I was able to interact with them, they worked fine. The problem arose again when I tried to reference them in the code. Exactly like the case with gms, I had code completion when trying to import up to the point of the actual class, and I could not declare the class in the code.
I was able to use the library by cloning it and importing the project.
Also, this is not an Android Studio problem because the same thing happens on the command line with "./gradlew clean build"
This is a current bug in Android Studio: https://code.google.com/p/android/issues/detail?id=64508 to be fixed this week.
The workaround is to close the project, delete the .iml files and .idea project and re-import the project.
Keep Your compile 'com.google.android.gms:play-services:4.0.30' as very first line in build.gradle dependencies like
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:+'
}
`
Open File> Project Structure and do the following steps
Select your main module in which you want to add dependency and click on OK.
Now try to import.
I think the most important question is what you want to achieve. Not all code is under this package. Not even sure which one is.
As noted before, this is a bug with Android Studio. It just don't recognize the path for classes and shows you like if there is an error. If you try compiling you'll see that everything just work fine.
A googler recently said it'll be addressed in this week release, so, be patient and lets see whats coming.
The fact that AS is in Preview mode tell us this sort of things are going to happen :)
Android studio is crazy one, I think.
It's removed "Import module" function and you can do "New module" only.
If you are developed on Eclipse, you need export all your projects to Gradle before switch to Androids studio (WTF?)
I prefer "IntelliJ IDEA Community Edition", although It's similar Android studio but it's better than Android studio (at least until now). You just import your project as eclipse format, IntelliJ IDEA will detect dependences libraries automatic (May be you need import jar libraries by hand) and rebuild project. That Done.

Categories

Resources