Android release build failing but debug version builds OK

Viewed 99

I'm working on a small Android Wear OS app and am pretty close to a release version.

The app is built in Android Studio using the Wear OS application template and it currently has just the one Activity (MainActivity).

Up to now I have been building a debug variant without any problems. I didn't need to tweak anything to make that work.

But now I am trying to build a release variant I am getting the following error:

Error: MainActivity must extend android.app.Service [Instantiatable]

My AndroidManifest.xml is as follows and it's the <service android:name="MainActivity" that is flagging as the error in the editor with MainActivity underlined in red:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.DeviceDefault">
    <uses-library
        android:name="com.google.android.wearable"
        android:required="true" />

    <meta-data
        android:name="com.google.android.wearable.standalone"
        android:value="true" />

    <!-- Recommended for Android 9 (API level 28) and lower. -->
    <!-- Required for Android 10 (API level 29) and higher. -->
    <service
        android:name="MainActivity"
        android:foregroundServiceType="location" >
    <!-- Any inner elements would go here. -->
    </service>


    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

My MainActivity currently extends Activity

public class MainActivity extends Activity {

I have no idea how to resolve this... it doesn't make sense to me that the debug variant builds and runs fine but the release variant doesnt.

The only release build specific stuff in my build.gradle is:

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

When I switch back to the debug variant the app build and runs perfectly on both an AVD Wear OS device and on an actual device.

0 Answers
Related