Adding Google Play Services to non-gradle Android Studio project? - java

I have an existing project that was built without gradle for Android Studio
and I'm trying to get Google Play Services imported to fix a
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable exception.
The only problem is it doesn't seem possible... I've considered porting it to
gradle but the codebase is rather large (40+ Activities) and it would be a
nightmare for someone like me, who's never used gradle before, to accomplish.
I've trying importing the Google Play Services project from the SDK but it
hangs forever "creating gradle files".
Anyone have any experience loading this library to a non-gradle project before?
As an aside, I've tried loading the project into Eclipse to see if I could do
something that way, but the build paths self-destruct to where I've spent hours
trying to sort through them to no avail.

Copy the library from the SDK/Extras Directory
Use your SDK Manager to download the Google Play Services - it'll be found under the Extras directory.
Go to your Android SDK directory and find the google-play-services_lib directory, for me this was in the Android Studio package:
/Applications/Android Studio.app/sdk/extras/google/google_play_services/libproject/google-play-services_lib/
Copy this entire directory to your project's libs directory.
Add this as a module dependency as you normally would. (For Android Studio, see below for step-by-step instructions.)
You'll need to add a meta-tag to your AndroidManifest.xml file as well, that looks like this:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Profit and Party?
Android Studio Steps
Steps to add the library project as a module dependency once it's already in your libs directory.
File > Import Module.
Select the google-play-services_lib directory under your libs directory.
Ensure Create module from existing sources is selected and click Next until you finish the wizard.
Project Structure > Modules (far left) > Select Your App > Dependencies tab > + > Module Dependency > google-play-services_lib.
Project Structure > Modules (far left) > Select google-play-services_lib > Dependencies tab > + > Jars or directories... > Find and select libs/google-play-services_lib/libs/google-play-services.jar.
Make sure you click the Export checkbox for this dependency.
Profit and Party?
Many thanks to Adama Speakman's post for the specific Android Studio steps.
JP

Related

How to install Android library in Android Studio?

I'm trying to install the supertooltips library and I fail every time.
I followed many tutorials, but I ended up with
Error:Configuration with name 'default' not found.
Are all the folders and files in the zip necessary, or do I have to put a specific folder in my library folder "myproject/mylibs"? And when I try to add the library from file>new>import module or right click project > new > module > import Gradle project and choose the library; it says project already contains module with this name "app" folder.
I'm using the Android Studio 1.5.
Just add this to your dependencies in your Module:app build.gradle:
dependencies {
compile 'com.nhaarman.supertooltips:library:3.0.+'
}
Simply add that line and then just rebuild the project and the library will be added.

External library dependency under Android Studio

I have my Android Studio project structured as follow:
/mysdk
-manifests
-java
-com.xxx.sdk
-ext-libs
-com.yyy.lib (not .jar but .java files instead)
-res
/app
-manifests
-java
-res
I can include com.yyy.lib.* inisde com.xxx.sdk and reference all the methods without any symbol resolution problem in Eclipse project.
But after I transfer my IDE from Eclipse to Android Studio and it tells me it cannot resolve the symbols/methods from com.yyy.lib inside com.xx.sdk (ex: com.xxx.sdk.Activty.java)
How can I fix this dependency problem in Android studio?
If you have no strong preference for the location of com.yyy.lib, just moving it into the parent (is it src/main/java? based on gradle convention) it will probably get picked up.
It appears the IDE is treating src/main/java (or whatever) as a source folder and your package paths aren't matching up with your directory structure
ext-libs.com.yyy.lib instead of com.yyy.lib
That's because Android Studio uses Gradle as its dependency manager, whereas Eclipse uses either Maven or Ant.
You can read more about managing dependencies with Gradle, here.
This answer explains how to add a dependency/library to Gradle in Android Studio.
In your project file browser:
Go to libs folder. and add your library if not present
and then in gradle: add compile files('libs/your_library') in dependencies and then Sync Gradle

How Do I Import a Non-Android Eclipse Maven Project into Android Studio?

I am starting at a disadvantage as I know neither Eclipse, Gradle or Android Studio. As such, I may not be using the correct terminology for everything, but I'll give it a shot. My ultimate goal is to get a working Eclipse-based Android app imported into Android Studio and hand it back to the Android developer. This question is about a problem I encountered on the way.
I have successfully imported the main Android project into AS. Now I'm trying to pull in another project it depends upon as a module. The dependency is a Maven project. It has a pom.xml, a .project and a .classpath. It's not an Android project, so there's no AndroidManifest.xml. It has a src but no res folder. I want this project to be a module rather than an external dependency as the developer will modify the source code on occasion.
The problem is that AS refuses to accept the project as an importable module. The Add Module dialog, when pointed to the project's root directory, continues to warn that I haven't yet selected a valid Android Eclipse or Gradle project. The Next button stays grayed-out. I agree that this is neither an Android-specific nor a Gradle project, but I have read here that IntelliJ IDEA will import such projects. It appears that AS will not.
There are several other non-Android Eclipse projects that also won't import as modules in the same way. These include ordinary Maven and ant-based libraries.
How do I accomplish this? The GUI seems out to thwart me. If I get down to the Gradle XML level, can I do it and will the modules show up normally in the GUI? Do I have to go back to Eclipse and convert these to Gradle projects first?
Thanks in advance.

How can I bring Google play services into my libGDX Gradle project?

After adding Google Play Services to integrate Google ads into my libGDX project in Eclipse, I can no longer use Gradle to build my Android project.
I know that's because I need to tell Gradle about the new Google Play project dependency so I added compile com.google.android.gms:play-services:5.0.89 to the dependencies section of the :android project however it complains that it could not find com.android.support:support-v4:19.1.0.
I guess that means I need to somehow tell Gradle this new dependency depends on another dependency?
Everything works fine in Eclipse so the dependency of my Google Play project in Eclipse is for sure golden, I just need to make Gradle the same way. Do I need to declare the Google play project as another Gradle project and make a build.gradle file for it? I don't think I should be touching the Google Play project contents at all.
If you have downloaded the tools and google reprositories using the Android SDK Manager (1st thing to check), check if your build.gradle files do not need to be updated (what libGDX version are you currently using?).
I had the same problem and solved it by replacing my Android's module build.gradle file by a brand new.
To do so, use the last ligdx setup ui (https://github.com/libgdx/libgdx/wiki/Project-Setup-Gradle) to create a fresh project then compare/replace gradle files.
Under your android module there's a build.gradle file. Add the following:
dependencies {
compile 'com.google.android.gms:play-services:6.1.11'
}
Check for the latest version of Google Play Services and update your version number accordingly.

package com.google.android.gms.maps.model does not exist

I am in Android Studio and this is a NON GRADLE project.
I have installed google play services, and google repository through sdk manager. I have imported google-play-services_lib as a module and added the google-play-services.jar as a library.
Yet for some reason my android-maps-utils files can't find my play services references.
import com.google.android.gms.maps.model.LatLng
in com.google.maps.android.clustering.Cluster.java says model doesn't exist.I can see the file in the play services library inside my project as shown below:
So why can't this file pick it up?:
I had to add dependencies for my project and each of my 3rd party libraries.
In Android Studio File > Project Structure > Libraries > choose a library > on the bottom of the dialog there should be a + button. Click that and then add dependencies. I think I added them as libraries (whatever the second option was)

Categories

Resources