While working for the Arduino Mega ADK, I struggled in getting things to work. Then I realized that using Google APIs for my project resolves the issues. So here are the steps I followed on configuring Google APIs for Android Studio. Don't get scared, these are very simple steps.
Step 1: Install Google APIs and Google Play Services from SDK Manager
This can be done from both Android Studio and from windows start menu. I will walk you through the Android Studio method. On the to ribbon of Android studio go to "Tools -> Android " and click on "SDK Manager"
In the SDK Manager window, select the Google APIs version. In my case the version was Android 4.4.2 (API 19). Select the other packages as shown in the below image and click install package
Step 2: Modify the gradle file of your project
Once the installation is finished from the above step, Open your project in android studio and navigate to your gradle file. You can find this in the left hand side pane.
Double click on the file to open it in the editor.
Change :
compileSdkVersion "19"
To:
compileSdkVersion "Google Inc.:Google APIs:19"
Where as 19 is the sdk version, I intended to compile with. Change all 19's to whatever version you wan to compile with. And comment the "compile 'com.android.support:appcompat-v7:23.+'" and sync/build the project.
Here is my complete gradle file
Step 3: Remove everything related to app compat
As we commented "compile 'com.android.support:appcompat-v7:23.+'" in the gradle, you will see many errors. Don't worry, this is all part of the game.
Navigate to app -> res -> values -> styles. Open the styles file and
change:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="AppTheme">
Navigate to app -> res -> menu -> menu_main.xml. Open the file and delete the item tag. So the file looks like:
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> </menu>
Navigate to MainActivity and remove import "import android.support.v7.app.ActionBarActivity;"
In the main activity change the extents ActionBarActivity to Activity i.e., change
public class MainActivity extends ActionBarActivity {
to
public class MainActivity extends Activity {
From the main activity also delete the below code:
if (id == R.id.action_settings) { return true; }
That is all. Now your project is ready and should compile using Google API's without errors.
References:
Thanks to Su-Au Hwang from Stackoverflow
Post a Comment