Flutter, how to have release and debug app on the same device? - android

I'm working with flutter on an application (only android for now) which can be downloaded from Google Play.
I have installed the released app on my phone. However, whenever I launch the debug on my device with android studio, it is deleting the released version.
What I would want is having both apps at the same time, like "App" and "App_debug" on my device.
How can I set up my project so there is no conflict between the debug and the release app ?
Thank you.

I managed to found a solution (only for android).
To not delete the "released App" download from Google Play, I add these lines in the file android/app/build.gradle:
android {
buildTypes {
// ------ Start Changes -----
debug {
applicationIdSuffix ".debug"
}
// ----- End Changes -----
}
}
In that way the package will be com.example.app for a release app and com.example.app.debug for my debug app and there is no conflict anymore.
However I also wanted a different app name so I can differenciate both apps.
To do so I followed this comment:
In the file android/app/src/main/AndroidManifest.xml I made this change:
<manifest ...>
<application
// before : android:label="App"
android:label="#string/app_name" // <- After my changes
>
</application>
</manifest>
Then to set up the name for the release app, create or modify the file android/app/src/main/res/values/string.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App</string>
</resources>
And for the debug version, create or modify the file android/app/src/debug/res/values/string.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App Debug</string>
</resources>

What're you looking for is called flavors. You can check out more info about it in the flutter official docs or checking out these packages:
https://pub.dev/packages/flutter_flavor
https://pub.dev/packages/flutter_flavorizr

Related

App on Play store. Changed package name in Java. What part of Manifest needs old package name?

I released an app on Play store a few years ago.
The package name was com.X.Y.appName
This week, I found the old source code and got it all working in Android Studio 14.
I did not like the package name for my Java code to be com.X.Y.appName
So, I changed the Java code to com.Z.appName
The Java code was fine with that, and everything runs fine in the emulator testing.
However, I now want to release the new version in the Play store.
So, how do I release this new project that is recoded as package com.Z.appName to be released as an update to com.X.Y.appName ?
The manifest.xml file references the package twice
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Z.appName">
and
<activity android:name="com.Z.appName.MainActivity">
Which of these needs to remain in the original package name to keep this App release to be considered an update, and not a brand new app ?
I tried to revert the first package name under the manifest tag back to com.X.Y.appName, and my code would no longer compile. I am now getting "error: package R does not exist". So, I put it back to com.Z.appName.
If I change the 2nd one in the activity tag, the code turns red, and I get "Class not found" error.
So, how do I release this new project that is recoded as package com.Z.appName to be released as an update to com.X.Y.appName ?
Do I leave the 2 entries above in manifest.XML to retain the new package name of com.Z.appName, but revert to the original com.X.Y.appName somewhere else entirely?
Build. Gradle?
I think I found a way. Does this seem correct?
I changed the manifest to the original package name
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.X.Y.appName">
Then I added this in MainActivity.java
import com.X.Y.appName.R;
The project now compiles and works, and the manifest has the old project name.
Do I need to edit build.gradle as well ?
Currently, it shows the new package name
defaultConfig {
applicationId "com.Z.appName"

How can I change the app display name build with Flutter?

I have created the app using Flutter create testapp.
Now, I want to change the app name from "testapp" to "My Trips Tracker". How can I do that?
I have tried changing from the AndroidManifest.xml, and it got changed, but is there a way that Flutter provides to do that?
Android
Open AndroidManifest.xml (located at android/app/src/main)
<application
android:label="App Name" ...> // Your app name here
iOS
Open info.plist (located at ios/Runner)
<key>CFBundleDisplayName</key>
<string>App Name</string> // Your app name here
and/or
Don't forget to stop and run the app again.
UPDATE: From the comments this answer seems to be out of date
The Flutter documentation points out where you can change the display name of your application for both Android and iOS. This may be what you are looking for:
Preparing an Android App for Release
Preparing an iOS App for Release
For Android
It seems you have already found this in the AndroidManifest.xml as the application entry.
Review the default App Manifest file AndroidManifest.xml located in
/android/app/src/main/ and verify the values are correct,
especially:
application: Edit the android:label in the application tag to reflect the final name of the
app.
For iOS
See the Review Xcode project settings section:
Navigate to your target’s settings in Xcode:
In Xcode, open Runner.xcworkspace in your app’s ios folder.
To view your app’s settings, select the Runner project in the Xcode project
navigator. Then, in the main view sidebar, select the Runner target.
Select the General tab. Next, you’ll verify the most important
settings:
Display Name: the name of the app to be displayed on the home screen
and elsewhere.
There is a plugin called flutter_launcher_name.
Write file pubspec.yaml:
dev_dependencies:
flutter_launcher_name: "^0.0.1"
flutter_launcher_name:
name: "yourNewAppLauncherName"
And run:
flutter pub get
flutter pub run flutter_launcher_name:main
You can get the same result as editing AndroidManifest.xml and Info.plist.
You can change it in iOS without opening Xcode by editing the project/ios/Runner/info.plist <key>CFBundleDisplayName</key> to the String that you want as your name.
FWIW - I was getting frustrated with making changes in Xcode and Flutter, so I started committing all changes before opening Xcode, so I could see where the changes show up in the Flutter project.
Review the default app manifest file, AndroidManifest.xml, located in <app dir>/android/app/src/main
Edit the android:label to your desired display name
There are several possibilities:
1- The use of a package:
I suggest you to use flutter_launcher_name because of the command-line tool which simplifies the task of updating your Flutter app's launcher name.
Usage:
Add your Flutter Launcher name configuration to your pubspec.yaml file:
dev_dependencies:
flutter_launcher_name: "^0.0.1"
flutter_launcher_name:
name: "yourNewAppLauncherName"
After setting up the configuration, all that is left to do is run the package.
flutter pub get
flutter pub run flutter_launcher_name:main
If you use this package, you don't need modify file AndroidManifest.xml or Info.plist.
2- Edit AndroidManifest.xml for Android and info.plist for iOS
For Android, edit only android:label value in the application tag in file AndroidManifest.xml located in the folder: android/app/src/main
Code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Your Application Name" //here
android:icon="#mipmap/ic_launcher">
<activity>
<!-- -->
</activity>
</application>
</manifest>
Screenshot:
For iOS, edit only the value inside the String tag in file Info.plist located in the folder ios/Runner .
Code:
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>Your Application Name </string> //here
</dict>
</plist>
Screenshot:
Do a flutter clean and restart your application if you have a problem.
A few of the answers here suggest using the package flutter_launcher_name, but this package is no longer being maintained and will result in dependency issues within new Flutter 2.0 projects.
The plugin flutter_app_name (https://pub.dev/packages/flutter_app_name) is a nearly identical package that has sound null safety and will work with Flutter 2.0.
Set your dev dependencies and your app's name
dev_dependencies:
flutter_app_name: ^0.1.1
flutter_app_name:
name: "My Cool App"
Run flutter_app_name in your project's directory
flutter pub get
flutter pub run flutter_app_name
Your launcher will now have the name of "My Cool App".
You can change it in iOS without opening Xcode by editing file *project/ios/Runner/info.plist. Set <key>CFBundleDisplayName</key> to the string that you want as your name.
For Android, change the app name from the Android folder, in the AndroidManifest.xml file, android/app/src/main. Let the android label refer to the name you prefer, for example,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<application
android:label="test"
// The rest of the code
</application>
</manifest>
You can change the Application name, by updating the name for both Android and iOS
for Android
just open AndroidManifest.xml file by,
go to inside android>app>src>main>AndroidManifest.xml
like this:-
so my application name is a "demo" so, I will update the label value.
same as for iOS
just open Info.plist file by,
go to inside ios>Runner>Info.plist
like this:-
And change this string value.
One problem is that in iOS Settings (iOS 12.x) if you change the Display Name, it leaves the app name and icon in iOS Settings as the old version.
For Android, change the app name from the Android folder. In the AndroidManifest.xml file, in folder android/app/src/main, let the android label refer to the name you prefer, for example,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<application
`android:label="myappname"`
// The rest of the code
</application>
</manifest>
You can easily do this with rename package, It helps you to change your Flutter project's AppName and BundleId for different platforms, currently available for IOS, Android, macOS and Web
To install the package run the following command:
pub global activate rename
To rename the App, use the following command:
pub global run rename --appname "Your App Name"
That's It!
You can check the documentation of the package for full details because it has some nice features to choose the target platform and more.
As of 2019-12-21, you need to change the name [NameOfYourApp] in file pubspec.yaml. Then go to menu Edit → Find → Replace in Path, and replace all occurrences of your previous name.
Also, just for good measure, change the folder names in your android directory, e.g. android/app/src/main/java/com/example/yourappname.
Then in the console, in your app's root directory, run
flutter clean
in case you are releasing for multi-localizations (languages).
for Android:
in your app folder at
[appname]\android\app\src\main\res
add locale folders for example:
values-ar
valuse-en
then inside each folder add a new strings.xml that contains the app name in that language.
for ar
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="app_name">ادارة الديون</string>
</resources>
for en
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="app_name">debt management</string>
</resources>
The last thing you can do is go to your AndroidManifest.xml file
and set the android:label to the new files you have created.
android:label="#string/app_name"
I saw indeed the manual solution (to go to IOS and Android). But I found out a plugin which enables changing name from one single location:
https://pub.dev/packages/flutter_launcher_name
Just do the following:
Add to pubspec.yaml
dev_dependencies:
flutter_launcher_name: "^0.0.1"
flutter_launcher_name:
name: "yourNewAppLauncherName"
Run in Terminal:
flutter pub get
flutter pub run flutter_launcher_name:main
Done.
First
Rename your AndroidManifest.xml file
android:label="Your App Name"
Second
Rename Your Application Name in Pubspec.yaml file
name: Your Application Name
Third
Change Your Application logo
flutter_icons:
android: "launcher_icon"
ios: true
image_path: "assets/path/your Application logo.formate"
Fourth
Run
flutter pub pub run flutter_launcher_icons:main
If you like to automate stuff from command line like me, you can use this
appName="TestApp"
declare -a androidAppTypes=(
"main"
"debug"
"profile"
)
# Change app name for Android
for appType in ${androidAppTypes[#]}
do
xmlstarlet ed -L -u '/manifest/application/#android:label' -v "$appName" android/app/src/$appType/AndroidManifest.xml
done
# Change app name for Android
plutil -replace CFBundleDisplayName -string "$appName" ios/Runner/Info.plist
The way of changing the name for iOS and Android is clearly mentioned in the documentation as follows:
Build and release an Android app
Build and release an iOS app
But, the case of iOS after you change the Display Name from Xcode, you are not able to run the application in the Flutter way, like flutter run.
Because the Flutter run expects the app name as Runner. Even if you change the name in Xcode, it doesn't work.
So, I fixed this as follows:
Move to the location on your Flutter project, ios/Runner.xcodeproj/project.pbxproj, and find and replace all instances of your new name with Runner.
Then everything should work in the flutter run way.
But don't forget to change the name display name on your next release time. Otherwise, the App Store rejects your name.

Cannot build Linphone android with different package name

I am trying to build Linphone android from this, with SDK api 23 and NDK r11c on Ubuntu 16.10. I already built it successfully but I cannot change its package name so as to be able to upload it to Google Play Store despite following its instruction to the letter. For Example:
To create an apk with a different package name
You need to edit the custom_rules.xml file:
look for the property named "linphone.package.name" and change it value accordingly
Already done:
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<property name="linphone.package.name" value="my.name" />
....
Then I did this
also update the values in the AndroidManifest file where the comment appears
by replacing all instances of org.linphone in every <!-- Change package ! --> comment. All of them are comments though so that may be not important. I did not change this one because it will throw an error when I run make
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.linphone"
android:installLocation="auto"
android:versionCode="3253"
android:versionName="3.2.5">
And the next step is
change the package name also in the files: res/xml/syncadapter.xml, res/xml/contacts.xml and res/values/non_localizable_custom where appears
which I did exactly like I was told. The last step is running make.
But the result I always get is org.linphone no matter whichever name I changed it to. Did I botched any step? Can we even change linphone package name to something other than org.linphone? And no, I cannot change its package name by this method, it would just brick the project, render it unbuildable.
Now the package name are in build.gradle and no more in custom_rules.xml
def getPackageName() {
return "org.linphone"
}
and its used here:
defaultConfig {
compileSdkVersion 23
buildToolsVersion "25.0.2"
applicationId getPackageName()
multiDexEnabled true
}

Android upload new apk to production failed: Use different version code

I've build an app using PhoneGap and I used PhoneGap Build to build the actual apk. Initially I uploaded an apk, realised that there was a bug. I then unpublished it and am now at the stage where I have to re-upload a new apk. However when I do I get the following error:
My initial idea is that I have to change something in my config.xml file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.example.myapp"
version="1.0.0"
xmlns="http://www.w3.org/ns/widgets"
xmlns:gap="http://phonegap.com/ns/1.0"
versionCode="1.0">
.....
Though I've tried changing both instances where there's a reference to 'code 1' and nothing works. What am I doing wrong?
In your config.xml
change this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.prosperitygroup.EmedEmergency"
version="1.0.0"
xmlns="http://www.w3.org/ns/widgets"
xmlns:gap="http://phonegap.com/ns/1.0"
versionCode="1.0">
to this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.prosperitygroup.EmedEmergency"
version="1.0.1"
xmlns="http://www.w3.org/ns/widgets"
xmlns:gap="http://phonegap.com/ns/1.0"
versionCode="2">
I am assuming here that your config.xml is a wrapper for AndroidManifest.xml inside Cordova (or the new build.gradle way of increasing version numbers).
If you do have an AndroidManifest then you want something like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prosperitygroup.EmedEmergency"
android:versionCode="2"
android:versionName="1.1" >
You must increase the version number of your app when uploading a new version, you can increase the number by 1, 2 or any other numerical number.
You should increase the version number for every bug fix that you check in to source control. That way you can keep track of bugs easier.
For example, if you check in a bug fix with build number of 1.8 and someone reported the bug in 1.7 then you can tell the person to simply update for a bug fix.
I try and increase my version code with every bug fix I make, when I close a bug report, I make a note of the new build code so that I know to ignore bug reports from users on an old version which has the bug present
What is the difference between versionCode and version?
Version Code
— An integer value that represents the version of the application
code, relative to other versions. The value is an integer so that
other applications can programmatically evaluate it, for example to
check an upgrade or downgrade relationship. You can set the value to
any integer you want, however you should make sure that each
successive release of your application uses a greater value. The
system does not enforce this behavior, but increasing the value with
successive releases is normative.
android:versionName
— A string value that represents the release version of the
application code, as it should be shown to users. The value is a
string so that you can describe the application version as a
.. string, or as any other type of absolute or
relative version identifier.
You can read more about them here in the android docs:
At the start of your manifest, there is a attribute for versionCode and versionName as such:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.basiccontactables"
android:versionCode="1"
android:versionName="1.0" >
You need to update those two variables each time you want to publish another version of your apk.

android apk upload not working because name not valid

I have signed and zipalign my android application and now wishes to upload it on the play store.
I however get the following message when I am done uploading it:
Upload failed
Your APK's package name must be in the following format "com.example.myapp". It may contain letters (a-z), numbers, and underscores (_). It must start with a lowercase character. It must be 150 characters or fewer.
My apk name is
dd.afm.aftermath.apk
So I don't understand why it does not comply?
Thanks in advance
Change your AdnroidManifest.xml file's package value from "AndroClient.AndroClient" to "com.example.myapp" (or whatever).
Then Xamarin will use it when compiling.
The error message complains about the 'package name', not about the APK file name.
Your package name is set to 'AndroClient.AndroClient', which does not match the prescribed pattern of com.example.app. Change your package name to something like com.dualdub.androclient.
background
The package name and version code is what identifies an app. Increase the version code, while keeping the same package name, and people will get automatically updated to the new version. Change the package name and the Google Play Store considers it a different app.
As you probably know, there are now millions of published apps. To prevent package name clashes the prescribed way is to prefix your app's name with your website domain in reverse. In your profile it says that http://dualdub.com is your website. So you should prefix your app's name with "com.dualdub.". Package names are case-sensitive; it is common practice to use all lower case.
Google Play Store reads your package name from the AndroidManifest.xml, from the 'manifest' element; 'package' attribute. How to change that depends on your IDE.
Change package name with Android Studio
When you are using Android Studio you are also using the Gradle build system. The Gradle build system overrides the package name in the manifest for you. During the build it puts the applicationId in the manifest package attribute.
Open the build.gradle file in your app module. It should be located at: <projectDir>/app/build.gradle. It should look something like this:
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.example.appname"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Update the applicationId to be com.dualdub.androclient.
Change package name with Eclipse
To be honest, I have never used Eclipse so I will have to give you vague directions.
In the AndroidManifest.xml you have the manifest package attribute. It plays a dual role: 1) it specifies the package name (also known as the applicationId), 2) it helps shorten class names that you specify with other elements, e.g. when specifying activities you can write android:name=".MainActivity" instead of android:name="com.example.appname.MainActivity".
To change the package name you will actually have to change the namespace of your code. In your .java files change the first line from 'package AndroClient.AanroClient;' to package com.dualdub.androclient;.
Most likely, Eclipse will have a refactoring tool to rename java packages to make this easier for you.
As the error says:
It must start with a lowercase character
While your package name is: AndroClient.AndroClient, which starts with an upper case letter.
Citing from the documentation:
Package Name is the package namespace for your app (following the same rules as packages in the Java programming language). Your package name must be unique across all packages installed on the Android system. For this reason, it's generally best if you use a name that begins with the reverse domain name of your organization or publisher entity. For this project, you can use something like "com.example.myfirstapp." However, you cannot publish your app on Google Play using the "com.example" namespace.
I'd suggest to just conform to the "reverse domain" rule of thumb
its the problem of your package..
Change your package name as remove example from it..
eg:
com.developer.name
The first line of your java source probably has the package name.
package com.gosylvester.hilbilyfashliegt;
The package name is also in the manifest.
The app name or what you call the app is setup in the manifest for android:label
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gosylvester.hilbilyfashliegt"
android:versionCode="7"
android:versionName="Juger" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.gosylvester.hilbilyfashliegt.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Generally you would store the app name in the res/values/strings.xml below app_name is the app name.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Hil Bily FashLiegt</string>
<string name="action_settings">Make stays</string>
<string name="author" translatable="false">by cousin Dan</string>
<string name="new_this_version">""New this one. Stil Kant make wir catch stay on good. Toch screen to mak er on. Use make stays for duk tap wird"</string>
<string name="aboutcheckbox">Reckon not show this here agin</string>
<string name="shareText">I reckon this here hillbile fashliegt app is worth a jar of moonshine. https://play.google.com/store/apps/details?id=com.gosylvester.hilbilyfashliegt</string>
<string name="sharesubject">Android add free flashLight App by Dan Sylvester</string>
<string name="about_firstrun">com.gosylvester.hilbilyfashliegt.firstrunabout</string>
<string name="preferences">com.gosylvester.hilbilyfashliegt.prefrences</string>
</resources>

Categories

Resources