Reputation: 10328
Adding the v7 appcompat support library to my build.gradle, I can use ActionBarActivity with no problems. But if I replace ActionBarActivity
with AppCompatActivity
, I get:
./gradlew assembleDebug
:preBuild
:compileDebugNdk UP-TO-DATE
:preDebugBuild
:checkDebugManifest
:preReleaseBuild
:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:prepareDebugDependencies
:compileDebugAidl UP-TO-DATE
:compileDebugRenderscript UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:generateDebugAssets UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:mergeDebugResources UP-TO-DATE
:processDebugManifest UP-TO-DATE
:processDebugResources UP-TO-DATE
:generateDebugSources UP-TO-DATE
:compileDebugJava
MainActivity.java:4: error: cannot find symbol
import android.support.v7.app.AppCompatActivity;
MainActivity.java:
package app.test.v7.support;
// replacing ActionBarActivity with AppCompatActivity fails.
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
// replacing ActionBarActivity with AppCompatActivity fails.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
manifest has:
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="21" />
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.0"
defaultConfig {
targetSdkVersion 21
}
}
dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
}
The Android developer docs indicate that ActionBarActivity
itself derives from AppCompatActivity
and recommends using AppCompatActivity
instead of (the now deprecated) ActionBarActivity
.
Any ideas why the class cannot be found during the build?
Upvotes: 1
Views: 7086
Reputation: 141
With todays latest version nothing worked, until upgrading the settings.gradle gradle version fixed it (it was 2.1.3) something in gradle toolchain seems to classpath 'com.android.tools.build:gradle:2.2.3'
Upvotes: 1
Reputation: 10328
Thanks to @CommonsWare for the suggestions in the comments.
Updating the support library version to v22.2 in build.gradle:
compile 'com.android.support:appcompat-v7:22.2.0'
sorted the problem.
Really wish this was mentioned in the Android docs (particularly since ActionBarActivity
is now deprecated) but meh...
Upvotes: 5