Search code examples
androidandroid-actionbarandroid-actionbar-compat

ActionBar is not being displayed anymore after migration from Eclipse to Android Studio


I recently tried to edit my 4 year old android application in the recently appeared Android Studio 2.3.1. After importing the code I can launch it on my mobile phone. However the action bar seems to have disappeared. What has gone wrong? How can I tell android to display the action bar? I have implemented the action bar activity like this:

public class MainActivity extends ActionBarActivity

My build.gradle looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 17
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "de.my.app"
        minSdkVersion 8
        targetSdkVersion 17
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

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

I also tried to replace the compile command with something newer one:

compile 'com.android.support:appcompat-v7:25.3.1'

but already the syncing in android studio fails like this, throwing the following error:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library [com.android.support:appcompat-v7:25.3.1] /home/user/.android/build-cache/815cafa5312f1d889eb1134b2184a62b3f88d8a3/output/AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="android.support.v7.appcompat" to force usage

I haven't done much android coding in the last 4 years so I assume the ActionBar stuff has changed profoundly but shouldn't there be a way to compile the old code as it is using android studio?

Edit:
This is the manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.myApp.myAppDemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon_app"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="de.myApp.myAppDemo.Splash"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="de.myApp.myAppDemo.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape" 
            android:theme="@style/Theme.AppCompat.Light">
            <intent-filter>
                <action android:name="de.myApp.myAppDemo.MAINACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="de.myApp.myAppDemo.PropertiesAssign"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="de.myApp.myAppDemo.PROPERTIESASSIGN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="de.myApp.myAppDemo.PropertiesView"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="de.myApp.myAppDemo.PROPERTIESVIEW" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Solution

  • Meanwhile I got at least the ActionBar to be displayed. However I had to increase the MinSDK and targetSdkVersion / compileSdkVersion bigly: From 8,17 to 15,23. Moreover I had to look in the SDK-Manager to see which exact version of Android Support Library was installed on my system (23.2.0) and adapt the corresponding line in build.gradle.

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23      //->modified
        buildToolsVersion "25.0.0"
    
        defaultConfig {
            applicationId "de.Geo.geodraw"
            minSdkVersion 15      //->modified
            targetSdkVersion 23   //->modified
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }
    
    dependencies {
        compile "com.android.support:appcompat-v7:23.2.0"    //->modified
    }
    

    Not sure whether it was relevant or necessary but following this page I also added

    allprojects {
        repositories {
            jcenter()
            maven {                                 //->modified
                url "https://maven.google.com"      //->modified
            }                                       //->modified
        }
    }
    

    in another build.gradle file. If there is another solution without drastically changing minSdk and targetSdk I will accept that answer.