0

Im following the Android Tutorial at:

http://developer.android.com/training/basics/actionbar/setting-up.html

Im on part where we add the Action Bar. Im getting errors at every step.

1) First The tutorial first says to add this

<uses-sdk android:minSdkVersion="11" ... /> 

and then says to add this:

<uses-sdk android:minSdkVersion="7"  android:targetSdkVersion="18" />

at the end. So which should it be?

2) Second Another issue is that when I add the:

public class MainActivity extends ActionBarActivity { ... }

I get an error saying Cannot Resolve symbol ActionBarActivity.

So I go to set up the library:

http://developer.android.com/tools/support-library/setup.html

I already downloaded the Support Library. I have 2 build.gradle files. The one I think is the right one is at the same level as SRC, not inside it. And it looks like this in the end:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.+'
    // this is for your application
}

and then this to the MainActivity imports:

import android.app.ActionBar;
import android.support.v7.app.ActionBar;

But the word support in the second import is in red and cannot be resolved

Could not fine method compile() for arguments [com.android.support:appcompat-v7:18.0.+] on root project.

3) Third When I change my theme to this:

<activity android:theme="@style/Theme.AppCompat.Light" ... > 

I get a cannot resolve that line.

4) Fourth Finally since I changed my MainActivity extends to ActionBarActivity, in the manifest file I get a red line under:

        android:name="com.example.myfirstapp.MainActivity"

presumably because that class now has an error.

The tutorials doesn't seem to be up to date.

Im getting this error related to the ActionBarActivity... enter image description here

marciokoko
  • 4,988
  • 8
  • 51
  • 91

3 Answers3

1

You need to add the maven dependency in your module's gradle.build not in the project's gradle.build. It is the inner most gradle.build file. Then you should press the "Sync Project with Gradle Files" button. It should look something like this:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.0.1'
}

This assumes that you have the latest build tools installed.

Emmanuel
  • 13,083
  • 4
  • 39
  • 53
  • 2
    Ok it still gives me the Activity, ActionBar & v7.app.ActionBar imports as unused. It cannot resolve the v7.app.ActionBar app word or the ActionBarActivity extending the MainActivity class and a few others. – marciokoko Jan 26 '14 at 03:15
0

I just found this helpful link:

ActionBarActivity cannot resolve a symbol

It seems to be an Android Studio 0.4.2 bug.

Community
  • 1
  • 1
marciokoko
  • 4,988
  • 8
  • 51
  • 91
0

at the end. So which should it be?

ActionBar is introduced in API level 11 so

if you are supporting API levels lower than 11:

<uses-sdk android:minSdkVersion="7" ../> //like supporting API level 7 and above

As the ActionBar is not included in API, In order to use it you have to add support library as dependency in your project.

and your imports will be like

android.support.v7.app.ActionBar

If you are supporting only API level 11 and higher:

<uses-sdk android:minSdkVersion="11" ../> 

Nothing else needs to be done. You can use the classes like ActionBar comes with the API (level 11 and above).

and your imports will be like

android.app.ActionBar

Its clearly mentioned in the document your referring .

Note : In gradle build system minSdkVersion and targetSdkVersion defined in AndroidManifest will be overridden by what you define in your module's build.gradle file. So define them in build.gradle file not in manifest.

For adding support dependency in your project refer this

ActionBarActivity cannot resolve a symbol

Community
  • 1
  • 1
Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
  • After having to add this: import android.support.v7.app.ActionBarActivity; which is nowhere in the tutorial, just like the import android.widget.TextView is not in the tutorial when adding the SecondActivity. But I won't complain, I know how hard it is to keep tutorials up-to-date. :) – marciokoko Jan 26 '14 at 13:43