I\'ve always programmed Android with Eclipse and decided to start migrating to Android Studio. I decided to use the same SDK I already had for Eclipse, then:
I got the same problems. I solved my problem by updating gradle.build for each sub-module to latest compiler version.
This happens because after updates Android Studio uses API version 23 by default.
The following worked for me:
Press Ctrl + Shift + Alt + S to get to the project structure page. Go to the properties tab and change 23.0.0 to 22.0.1 (or equivalent to what you were using earlier) in the build tool area and rebuild your project.
If that doesn't work, go to gradle:app and then
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
Edit v7:23.0.0 to v7:22.2.1 as shown above and sync gradle. This will definitely work.
I agree with the previous answer. Your compile SDK version must match the support library. Here is what I did.
Then it should build without problem.
on module: app (Gradle)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.namepack.nameappxxxxx"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
project: nameAppXXXX (Gradle)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
and edit your activity of AppCompatActivity to for example Activity:
package com.namepack.nameappxxxxx;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class NameClass extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
}
}
If you've tried to change target to a previous GooglePlayServices or AppCompatv7 version and it doesn't work, check if you have any project-libraries dependency, this project will be targeting the latest version of any of these libraries. It happened to me with the Google Maps Utils Library project:
replace:
compile 'com.google.android.gms:play-services:+'
to
compile 'com.google.android.gms:play-services:8.3.0'
Then you can continue full targeting API 22
If it still doesn't compile, sometimes is useful to set compileSdkVersion API to 23 and targetSdkVersion to 22.
Make sure that all these are in upto date.