Re: Android Gradle packageNameSuffix doesn't actually rename package of the app

3,060 views
Skip to first unread message

Xavier Ducrohet

unread,
Jun 8, 2013, 2:25:13 PM6/8/13
to adt...@googlegroups.com
Are you asking if the package name suffix should change the package of the classes themselves? This is not what it does. It changes the package name in the manifest, which is what the system use as a unique identifier for apps.

The classes are untouched so that you can use the same classes for different apps from the same project.


On Sat, Jun 8, 2013 at 11:14 AM, Alexey Zakharov <alexey.v...@gmail.com> wrote:
Android Gradle packageNameSuffix doesn't actually rename package of the app. Is that desired behavior?

Currently in Intelli 12 there is an option rename package that also rename package of all application classes.

--
Alexey

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Alexey Zakharov

unread,
Jun 24, 2013, 3:10:55 AM6/24/13
to adt...@googlegroups.com
Can't run my project with debug prefix:

Launching application: com.example.debugpackage/com.example.debugpackage.MainActivity.
DEVICE SHELL COMMAND: am start -n "com.example.debugpackage/com.example.debugpackage.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.debugpackage/.MainActivity }
Error type 3
Error: Activity class {com.example.debugpackage/com.example.debugpackage.MainActivity} does not exist.


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
    package="com.example.debugpackage"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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>

</manifest>

build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }

    buildTypes {
        debug {
            packageNameSuffix ".debug"

Jonathan Steele

unread,
Jun 24, 2013, 2:29:40 PM6/24/13
to adt...@googlegroups.com
Did you check this one? Activity class {com.example.debugpackage/com.
example.debugpackage.MainActivity} does not exist.

Alexey Zakharov

unread,
Jun 26, 2013, 6:30:39 AM6/26/13
to adt...@googlegroups.com
It exist. Problem is caused by packagaNameSuffix setting.

Antony Tran

unread,
Jul 21, 2013, 10:04:48 AM7/21/13
to adt...@googlegroups.com
I am getting this problem too.

Let's say your original package name (in your Manifest) is 'com.example.android', and you use debug.packageNameSuffix = ".debug" to turn your app into 'com.example.android.debug' for debug builds.
Android Studio still tries to launch your app using the original package name, i.e. it executes the command:
'am start -n "com.example.android/com.example.android.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER'
The correct thing to do would be to execute:
'am start -n "com.example.android.debug/com.example.android.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER'

You can reproduce this by using a packageNameSuffix for the debug build type, and trying to build+run your app in Android Studio.

Fernando Dunn

unread,
Jul 23, 2013, 11:50:53 AM7/23/13
to adt...@googlegroups.com
Are you sure the device pushed the debug (unsigned) apk? I don't duplicate this issue.

Fernando Dunn

unread,
Jul 23, 2013, 12:03:00 PM7/23/13
to adt...@googlegroups.com
I use a debug suffix on an imported Eclipse project and I don't have this issue. If you're using packageNameSuffix = ".debug" it's strange that you would define your package as com.example.debugpackage? Shouldn't it be be com.example.package?

Likewise, since you're using the ".debug" prefix, I would think your error would be "Error: Activity class {com.example.debugpackage.debug/com.example.debugpackage.MainActivity} does not exist." I guess that would be the issue--assuming your device is actually pushing the debug/unsigned apk to the device.

You may want to try defining the packageName in your build.gradle and see if you get the same result. I do this for my flavors so that could be a difference.

Antony Tran

unread,
Jul 23, 2013, 5:50:13 PM7/23/13
to adt...@googlegroups.com
Seems like the issue only happens when Gradle and Android Studio become out of sync. Let's say you have .debug suffix and it is currently working fine. If you then modify the suffix in your your build.gradle to something else (e.g. .notdebug) and run your app, the APK will have the correct package but Android Studio will try to launch the Activity from the original package. If you uninstall the original app you will see the error mentioned above. Running 'Sync Project with Gradle Files' fixes the issue.

The APK created has the correct package. When this problem happens, it is only that Android Studio is launching the incorrect Activity. If we are expected to resync Android Studio/gradle after any modifications to build.gradle then maybe this is not a problem.

Fernando Dunn

unread,
Jul 24, 2013, 1:30:43 AM7/24/13
to adt...@googlegroups.com
I see what you mean. I think if you disabled the "Use auto-import" option, you have to sync build.gradle changes yourself. If you leave it on, any project structure changes are synced/imported automatically.
Reply all
Reply to author
Forward
0 new messages