I used react-native init MyApp to initialise a new React Native app.
This created among others an Android project with the package com.myapp.
What's the best way to change this package name, for example to: com.mycompany.myapp?
I tried changing it in AndroidManifest.xml but it created other errors, so I'm assuming it's not the way.
Any idea?
I've renamed the project' subfolder from: "android/app/src/main/java/MY/APP/OLD_ID/" to: "android/app/src/main/java/MY/APP/NEW_ID/"
Then manually switched the old and new package ids:
In:
android/app/src/main/java/MY/APP/NEW_ID/MainActivity.java:
package MY.APP.NEW_ID;
In android/app/src/main/java/MY/APP/NEW_ID/MainApplication.java:
package MY.APP.NEW_ID;
In android/app/src/main/AndroidManifest.xml:
package="MY.APP.NEW_ID"
And in android/app/build.gradle:
applicationId "MY.APP.NEW_ID"
In android/app/BUCK:
android_build_config(
package="MY.APP.NEW_ID"
)
android_resource(
package="MY.APP.NEW_ID"
)
Gradle' cleaning in the end (in /android folder):
./gradlew clean
I use the react-native-rename* npm package. Install it via
npm install react-native-rename -g
Then, from the root of your React Native project, execute the following:
react-native-rename "MyApp" -b com.mycompany.myapp
To change the package name from com.myapp to: com.mycompany.myapp (for example),
For iOS app of the react app, use xcode - under general.
For the android app, open the build.gradle at module level. The one in the android/app folder. You will find
// ...
defaultConfig {
applicationId com.myapp
// ...
}
// ...
Change the com.myapp to whatever you need.
Hope this helps.
you can simply use react-native-rename npm package.
Install using
npm install react-native-rename -g
Then from the root of your React Native project execute the following
react-native-rename "MyApp" -b com.mycompany.myapp
react-native-rename on npm
but notice that, this lib remove your MainActivity.java and MainApplication.java.
before changing your package name, give a backup from this two file and, after changing package name just put it back to their place. this solution work for me
more info:
react-native-rename
REACT 0.64 | 2021 NO EXPO
Let original App name be: com.myApp
Let New App Name: 'com.newname.myApp`
android\app\src\main\AndroidManifest.xml
Rename xml attribute: `package="com.newname.myApp"
android\app\src\main\java\com\[yourAppName]\MainActivity.java
Rename first line from package com.myApp; To package com.newname.myApp;
android\app\src\main\java\com\[yourAppName]\MainApplication.java
Rename first line To package com.newname.myApp;
In class private static void initializeFlipper
reneme this line:
Class<?> aClass = Class.forName("com.myApp.ReactNativeFlipper");
To
Class<?> aClass = Class.forName("com.newname.myApp.ReactNativeFlipper");
android\app\build.gradle
On the defaultConfig rename applicationId
to "com.newname.myApp"
Run on command line:
$ npx react-native start
$ npx react-native run-android
Goto Android studio
Right click your package (most probably com)-> Refractor -> Rename -> Enter new package name in the dialog -> Do Refractor
It will rename your package name everywhere.
In VS Code, press Ctrl + Shift + F and enter your old package name in 'Find' and enter your new package in 'Replace'. Then press 'Replace all occurrences'.
Definitely not the pragmatic way. But, it's done the trick for me.
If you are using Android Studio-
changing com.myapp to com.mycompany.myapp
create a new package hierarchy com.mycompany.myapp under android/app/src/main/java
Copy all classes from com.myapp to com.mycompany.myapp using Android studio GUI
Android studio will take care of putting suitable package name for all copied classes. This is useful if you have some custom modules and don't want to manually replace in all the .java files.
Update android/app/src/main/AndroidManifest.xml and android/app/build.gradle (replace com.myapp to com.mycompany.myapp
Sync the project (gradle build)
The init script generates a unique identifier for Android based on the name you gave it (e.g. com.acmeapp for AcmeApp).
You can see what name was generated by looking for the applicationId key in android/app/build.gradle.
If you need to change that unique identifier, do it now as described below:
In the /android folder, replace all occurrences of com.acmeapp by com.acme.app
Then change the directory structure with the following commands:
mkdir android/app/src/main/java/com/acme
mv android/app/src/main/java/com/acmeapp android/app/src/main/java/com/acme/app
You need a folder level for each dot in the app identifier.
Source: https://blog.elao.com/en/dev/from-react-native-init-to-app-stores-real-quick/
I have a solution based on #Cherniv's answer (works on macOS for me). Two differences: I have a Main2Activity.java in the java folder that I do the same thing to, and I don't bother calling ./gradlew clean since it seems like the react-native packager does that automatically anyways.
Anyways, my solution does what Cherniv's does, except I made a bash shell script for it since I'm building multiple apps using one set of code and want to be able to easily change the package name whenever I run my npm scripts.
Here is the bash script I used. You'll need to modify the packageName you want to use, and add anything else you want to it... but here are the basics. You can create a .sh file, give permission, and then run it from the same folder you run react-native from:
rm -rf ./android/app/src/main/java
mkdir -p ./android/app/src/main/java/com/MyWebsite/MyAppName
packageName="com.MyWebsite.MyAppName"
sed -i '' -e "s/.*package.*/package "$packageName";/" ./android/app/src/main/javaFiles/Main2Activity.java
sed -i '' -e "s/.*package.*/package "$packageName";/" ./android/app/src/main/javaFiles/MainActivity.java
sed -i '' -e "s/.*package.*/package "$packageName";/" ./android/app/src/main/javaFiles/MainApplication.java
sed -i '' -e "s/.*package=\".*/ package=\""$packageName"\"/" ./android/app/src/main/AndroidManifest.xml
sed -i '' -e "s/.*package = '.*/ package = '"$packageName"',/" ./android/app/BUCK
sed -i '' -e "s/.*applicationId.*/ applicationId \""$packageName"\"/" ./android/app/build.gradle
cp -R ./android/app/src/main/javaFiles/ ./android/app/src/main/java/com/MyWebsite/MyAppName
DISCLAIMER: You'll need to edit MainApplication.java's comment near the bottom of the java file first. It has the word 'package' in the comment. Because of how the script works, it takes any line with the word 'package' in it and replaces it. Because of this, this script may not be future proofed as there might be that same word used somewhere else.
Second Disclaimer: the first 3 sed commands edit the java files from a directory called javaFiles. I created this directory myself since I want to have one set of java files that are copied from there (as I might add new packages to it in the future). You will probably want to do the same thing. So copy all the files from the java folder (go through its subfolders to find the actual java files) and put them in a new folder called javaFiles.
Third Disclaimer: You'll need to edit the packageName variable to be in line with the paths at the top of the script and bottom (com.MyWebsite.MyAppName to com/MyWebsite/MyAppName)
If you are using VSCode and Windows.
1.Press Control + Shift + F.
2.Find Your Package Name and Replace All with your new Package Name.
type "cd android"
type "./gradlew clean"
To change the Package name you have to edit four files in your project :
1. android/app/src/main/java/com/reactNativeSampleApp/MainActivity.java
2. android/app/src/main/java/com/reactNativeSampleApp/MainApplication.java
3. android/app/src/main/AndroidManifest.xml
4. android/app/build.gradle
The first 2 files have the package name as something like below.
package com.WHATEVER_YOUR_PACKAGE_NAME_IS;
Change it to your desired package name.
package com.YOUR_DESIRED_PACKAGE_NAME;
You have to also edit the package name in 2 other files.
android/app/build.gradle
android/app/src/main/AndroidManifest.xml
Note if you have a google-services.json file in your project then you have to also change your package name in that file.
After this, you have to ./gradlew clean your project.
Go to Android Studio, open app, right click on java and choose
New and then Package.
Give the name you want (e.g. com.something).
Move the files from the other package (you want to rename) to the new Package. Delete the old package.
Go to your project in your editor and use the shortcut for searching in all the files (on mac is shift cmd F). Type in the name of your old package. Change all the references to the new package name.
Go to Android Studio, Build, Clean Project, Rebuild Project.
Done!
Happy coding :)
After running this:
react-native-rename "MyApp" -b com.mycompany.myapp
Make sure to also goto Build.gradle under android/app/...
and rename the application Id as shown below:
defaultConfig {
applicationId:com.appname.xxx
........
}
I will provide you step by step procedure.
First of all, we need to understand why we need to rename a package?
Mostly for uniquely identifying App right? So React Native is a cross-platform to develop an app that runs on both iOS and Android. So What I recommended is to need the same identifier in both the platforms. In case Android Package Name is a unique identifier of your App and for iOS its bundle ID.
Steps:
Firstly close all editors/studio eg: xcode android studio vscode and then Install package "react-native-rename" in the terminal by running the command (Keep your project folder copy in another folder for backup if you don't feel this safe):
npm install react-native-rename -g
After sucessfully installing package open your project folder in the terminal and hit the below command where "Your app name Within double quotes" is app name and <Your Package Name without double/single quotes> is replaced with package/bundle name/id:
react-native-rename "< Your app name Within double quotes >" -b <Your Package Name without double/single quotes>
Example: react-native-rename "Aptitude Test App" -b com.vaibhavmojidra.aptitudetestapp
Note Make sure the package/bundle name/id is all in small case
This is not yet done yet now every file will change where the it had bundle/package names except one in ios project which we manually need to do for that open the xcode>open a project or file> choose file from projectfolder/ios/projectname.xcodeproj and click open
Click on your projectname.xcodeproj that is first file in the project navigator then in field of Bundle identifier enter the package name/Bundle ID as below:
After that run in the terminal
cd ios
Then run
pod install
Then run
cd ..
Now you are done for all the changes for ios just last step is to open Android Studio>Open an Existing Project> select projectfolder/android folder > Click on open
Let it load and complete all the process and then in the Build Menu click "Clean Project" and the in File Menu > Close Project
Close All editors and Now You can try the commands to run project on ios and android it will run with renamed packaged just while start server add extra flag --reset-cache:
npm start --reset-cache
Enjoy it will work now
I fixed this by manually updating package name in following places
1) app.json | ./
2) index.js | ./
3) package.json | ./
4) settings.gradle | ./android/
5) BUCK | ./android/app/
6) build.gradle | ./android/app/
7) AndroidManifest.xml | ./android/app/src/main/
8) MainActivity.java | ./android/app/src/main/java/**
9) MainApplication.java | ./android/app/src/main/java/**
10)strings.xml | ./android/app/src/main/res/values
11)ReactNativeFlipper.java| ./android/app/src/debug/java/com/<package-name>/
There are a lot of bad answers here
if you want to change the package name, go to your build.gradle in app
defaultConfig {
applicationId "your.new.package.name" //change this line
then when running the app from the command line, pass in the new package name as an arg
react-native run-android --appId your.new.package.name
There's no need to rename your whole project
I use the react-native-rename* npm package. Install it via
npm install react-native-rename -g
Then, from the root of your React Native project, execute the following:
react-native-rename "MyApp" -b com.mycompany.myapp
very simple way :
cd /your/project/dir
run this command :
grep -rl "com.your.app" . | xargs sed -i 's/com.your.app/com.yournew.newapp/g'
rename your folder
android/app/src/main/java/com/your/app
change to
android/app/src/main/java/com/yournew/newapp
After renaming package name everywhere,
from android studio. File -> Invalidate caches/Restart may fix this type of errors
this worked for me
This information can be helpful for you so listen properly...
After updating package name and changing files, don't forget to change in
package.json and app.json file at the root directory of your react native project
Otherwise you will get this error below
Invariant Violation: "Your new package name" has not been registered
Ivan Chernykh's answer is correct for react-native 0.67 and below
For react-native 0.68 and above with the new architecture once you're down with the steps which Ivan Chernykh has mentioned
For android you have to go to app => src => main => jni folder
In MainApplicationTurboModuleManagerDelegate.h
change below line
static constexpr auto kJavaDescriptor =
"Lcom/yournewpackagename/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;";
In MainComponentsRegistry.h
constexpr static auto kJavaDescriptor =
"Lcom/yournewpackagename/newarchitecture/components/MainComponentsRegistry;";
I just learned this today but adding this answer to help others. You just need to add a namespace to the app/build.gradle that references the old name, like this:
defaultConfig {
applicationId "com.mycompany.myapp"
namespace "com.myapp"
}
Then you can have a bash script that changes the applicationId with something like this:
function sedi {
if [ "$(uname)" == "Linux" ]; then
\sed -i "$#"
else
\sed -i "" "$#"
fi
}
bundle_name=com.mycompany.myapp
sedi -E "s/applicationId \"[-0-9a-zA-Z._]*\"/applicationId \"${bundle_name}\"/" android/app/build.gradle
React Native#0.70.x
Tried to rename package name from com.x to com.y.z
I got through this painful process by doing these:
Change displayName in app.json to z.
{
"name": "<THIS_SHOULD_STAY_SAME>",
"displayName": "<Z>"
}
Change the content of the string app_name in strings.xml
<resources>
...
<string name="app_name"><Z></string>
...
</resources>
Search through your react-native project for com.x and replace all com.x with com.y.z
!important: In case you're using external services, and in case if
you're generated a file and put it under /android you may want to
make sure the services that you're using will still work. I recommend
you to generate a new config file(s) using your new package name
com.y.z and put it after the finishing the steps described below.
Update the folder structure to this:
old: .../android/app/src/main/java/com/x
new: .../android/app/src/main/java/com/y/z
Move all the files under .../android/app/src/main/java/com/x to .../android/app/src/main/java/com/y/z.
Clean up.
$ ./gradlew clean
Build.
$ react-native run-android
Go to file android/app/src/main/AndroidManifest.xml -
Update :
attr android:label of Element application as :
Old value - android:label="#string/app_name"
New Value - android:label="(string you want to put)"
and
attr android:label of Element activity as :
Old value - android:label="#string/app_name"
New Value - android:label="(string you want to put)"
Worked for me, hopefully it will help.
Related
We have a need to change the application id of a react native app, after the apk has been built. I am using "apktool d app.apk" to decode the apk. I then edit app/apktool.yml and change the renameManifestPackage from null to our new application id.
I then rebuild the apk with "apktool b app -o new-app.apk". Next I zipalign and resign the app. After doing this if I install the app on a device, I see that it has the new application id, but the logo on the launch screen does not show up. There are also some BuildConfig variables that are no longer set.
Is there someplace else that react-native uses the application id, that I would have to change it?
You used a wrong way for that!
I've changed project' subfolder name from: android/app/src/main/java/MY/APP/**OLD_ID**/ to: android/app/src/main/java/MY/APP/**NEW_ID**/
Then manually switched the old and new package ids:
android/app/src/main/java/MY/APP/NEW_ID/MainActivity.java:
package MY.APP.NEW_ID;
android/app/src/main/java/MY/APP/NEW_ID/MainApplication.java:
package MY.APP.NEW_ID;
android/app/src/main/AndroidManifest.xml:
package="MY.APP.NEW_ID"
android/app/build.gradle:
applicationId "MY.APP.NEW_ID"
(Optional) android/app/BUCK:
android_build_config(
package="MY.APP.NEW_ID"
)
android_resource(
package="MY.APP.NEW_ID"
)
Gradle' cleaning in the end ( /android folder):
./gradlew clean
I've created an app in react-native. I need the package name to be:
com.org.appname
React-native does not allow you to specify this as the package name in the init, or to change it after init.
react-native init --package="com.org.appname"
does not work
Changing the package name as described in Change package name for Android in React Native also doesn't work and results in the following error on react-native run-android
Failed to finalize session : INSTALL_FAILED_VERSION_DOWNGRADE
in iOS project you just need to change BundleID with Xcode.
In Android project you need to change package name in 4 files:
android/app/src/main/java/com/reactNativeSampleApp/MainActivity.java
android/app/src/main/java/com/reactNativeSampleApp/MainApplication.java
android/app/src/main/AndroidManifest.xml
android/app/build.gradle
good practice is also to modify BUCK file in Android project, in two places, and correspondingly adjust hierarchy in android project, although it is not necessary:
BUCK file:
android_build_config(
name = "build_config",
package = "app.new.name",
)
android_resource(
name = "res",
package = "app.new.name",
res = "src/main/res",
)
run command
./gradlew clean
According to this https://saumya.github.io/ray/articles/72/, you can run this command from the start
react-native init MyAwesomeProject -package "com.example.app"
But if you already generated your app via
react-native init MyAwesomeProject
You can modify app name in file
android/app/src/main/res/values/strings.xml
Then you can modify package name in files
android/app/src/main/java/com/reactNativeSampleApp/MainActivity.java
android/app/src/main/java/com/reactNativeSampleApp/MainApplication.java
android/app/src/main/AndroidManifest.xml ( optional as per my experience )
android/app/build.gradle
Lastly, run the following commands (from inside the app's android/ directory)
./gradlew clean
./gradlew assembleRelease
To change iOS version package name, use Xcode
I use the react-native-rename npm package.
Install using
npm install react-native-rename -g
Then from the root of your React Native project execute the following
react-native-rename "MyApp" -b com.mycompany.myapp
react-native-rename on npm
If your text editor able to replace a string in all of your project files it is very easy to change package id.
I am using PhpStorm and I just replaced my old.package.id with new.package.id in all of my project files. It worked for me
simply just change your package name in these 4 files
android => app => src => main => java => com => reactNativeSampleApp => MainActivity.java & MainApplication.java
android => app => src => main => AndroidManifest.xml
android => app => build.gradle
I'd like to know if some of you worked out how to generate signed APKs and IPA with multiple configurations (ie : beta for hockeyapp, and production for stores) in a single command.
I'm exploring all the possibilities there, it looks like there are lots of ways to do this.
I'd also like to be able to pass a variable like ENVIRONMENT to set Javascript constants such as an API url or turn on/off debugs.
Here's what I'm thinking right now :
Using https://www.npmjs.com/package/react-native-config to solve the former problem.
On android :
I'm thinking about adding a type in buildTypes in gradle. So far, I couldn't get it to work, I'm not very experienced with native configurations.
I would then make a bash script to create the offline bundle with the chosen env (staging / dev / prod) and use gradle's assembleRelease / assembleBeta. Do you think that's doable ?
On iOS, it looks a bit more complicated :
It looks like it's hard to change the project's configuration in CLI when building. So I was thinking that I should duplicate the project for each environement : project-dev.xcodeproj, project-prod.xcodeproj... you got the point.
Once again, I would make the bundle, then cp it inside the given project. A nice touch would be to trigger the xcode compilation in CLI too, I don't know if this is hard to set up.
What do you think about this ? Maybe some of you are already using custom scripts to do that ?
The icing on the cake would be to use HockeyApp's 'puck' cli tool to upload it, but that should be quite easy to set up once the application has been build for both iOS and Android.
This is the process I use for command line build with parameters. My system builds a release version .ips file and then copies and resigns that file with a development provisioning profile that I can put on my development devices to test exactly what is being sent to the customer or to the app store. Not all of this will be useful to you, but hopefully some will.
First, I have a variables file that sets the global parameters that I'm going to use for the build:
Scheme="(The scheme I am going to build inside my project)"
WindowsSavePath="(path to my source archive directory on a shared computer)"
InstallSavePath="(path to my .ipa archive directory on a shared computer"
Customer="(relative path inside archive directories)"
Fleet="(Continued relative path)"
PathToProject="(path to the folder on my Mac with the xcode project file)"
ProjectName="(project name).xcodeproj"
PlistPath="$Scheme-Info.plist"
appScheme="$Scheme"
AppName="(The name that I want to give my .ipa file)"
Version="(The version number for this build)"
AppendedFileName="-QA" //I use this for QA and Production distinction
exportPath="$InstallSavePath/$Fleet/$Customer/$Version$AppendedFileName/"
CompanyAppIdentifierPrefix="(my generic provisioning profile identifier)"
ArchiveLocation="$WindowsSavePath/$Fleet/$Customer/$Version$AppendedFileName"
SourceCodeDestination="(my compiled absolute path to the archive directories)"
This is all contained in a SetVariables.sh file. Now we get to start building the project. In another .sh file first I call the SetVariables file, then I start compilation:
#Update the version number in the plist file for the project
/usr/libexec/PListBuddy -c "Set :CFBundleShortVersionString $Version" "$PathToProject/$PlistPath"
/usr/libexec/PListBuddy -c "Set :CFBundleVersion $BuildVersion" "$PathToProject/$PlistPath"
#Now build and archive the project, the create the .ipa file for either submittal or giving to customers
mkdir -p "$exportPath"
mkdir -p "${ArchiveLocation}/dSYM"
xcodebuild -project "$PathToProject/$ProjectName" -scheme "$Scheme" DSTROOT="$exportPath" DEBUG_INFORMATION_FORMAT="dwarf-with-dsym" DWARF_DSYM_FOLDER_PATH="${ArchiveLocation}/dSYM" archive -archivePath "$exportPath${appScheme} $Version$AppendedFileName.xcarchive"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${exportPath}Applications/${AppName}.app" -o "${exportPath}${appScheme} $Version$AppendedFileName.ipa"
#Now resign and create an internal dev version to test on development ipads
rm -r Payload SwiftSupport
unzip -q "${exportPath}${appScheme} $Version$AppendedFileName.ipa"
BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "Payload/${AppName}.app/Info.plist")
. ./CreateInternalEntitlements.sh "$CompanyAppIdentifierPrefix.$BUNDLE_ID"
. ./resign.sh "${exportPath}${appScheme} $Version$AppendedFileName.ipa" "${exportPath}${appScheme} ${Version}${AppendedFileName} Internal" internalDev.mobileprovision "(My developer account tied to the internal provisioning profile" Entitlements.plist
rm -r Payload SwiftSupport
#Now delete the intermediate files from the installs directory
rm -rf "$exportPath${appScheme} $Version$AppendedFileName.xcarchive"
rm -rf "${exportPath}Applications"
I have left out a few things in there (resign.sh, createentitlements.sh), but those processes I found on stackoverflow, so it shouldn't be too hard for you to find as well.
I've never done it, but I'm relatively certain that you can change the command line arguments for the xcodebuild to build either release or debug like you are trying to do. You could also run the xcodebuild twice, once for debug and once for release, and save the builds to different locations.
I hope this helps you at least a little with your goals. This took my a week or two to put all together and get working for my needs. Good luck.
I'm working on Ionic project now whereby I want to zipalign the android-release-unsigned.apk file. I followed this guide by Ionic.
When I run zipalign -v 4 /Users/zulhilmizainudin/Desktop/kl-parking/platforms/android/build/outputs/apk/android-release-unsigned.apk android-release.apk command, I get -bash: zipalign: command not found error.
This is where zipalign sit in my system:
/Users/zulhilmizainudin/Library/Android/sdk/build-tools/21.1.2
I tried to copy zipalign inside it and put it inside my Ionic project folder and run the zipalign command again. But still get the same command not found.
What should I do now?
Solved!
I copied zipalign file from my Library/Android/sdk/build-tools/21.1.2 into my Ionic project folder
I add ./ in front of the zipalign command like this - ./zipalign -v 4 /Users/zulhilmizainudin/Desktop/kl-parking/platforms/android/build/outputs/apk/android-release-unsigned.apk android-release.apk
Done. Now I get android-release.apk inside my Ionic project folder.
Thanks to Michael for the solution!
If you're using Windows, the right way is to add path to zipalign.exe as PATH environment variable.
Finding where zipalign.exe is located in your PC, in my case this was
C:\Users\random-username\AppData\Local\Android\sdk1\build-tools\24.0.1
Then add this location as one of the entries in your PATH environment variable.
To avoid specifying or navigating to your sdk/build-tools/* directories each time you intend to build release version, you can simply add the path to your environment variable.
$ sudo nano ~/.bash_profile
copy and paste the below:
export PATH=${PATH}:/Library/Android/sdk/build-tools/21.1.2
You can then save and exit:
control + o // to save to file
control + x // to close the file
$ source ~/.bash_profile
You can then run your zipalign command from your project CLI directory.
This worked for me on Mac. Install and run Android Studio (important to start it one time).
Then find zipalign:
find ~/Library/Android/sdk/build-tools -name "zipalign"
Windows
the right way is to add path to zipalign.exe as PATH environment variable.
Finding where zipalign.exe is located in your PC, in my case this was
C:\Users\username\AppData\Local\Android\sdk1\build-tools\29.0.2
Then add this location as one of the entries in your PATH environment variable.
MAC
To avoid specifying or navigating to your SDK/build-tools/* directories each time you intend to build a release version, you can simply add the path to your environment variable.
$ sudo nano ~/.bash_profile
copy and paste the below:
export PATH=${PATH}:/Library/Android/sdk/build-tools/21.1.2
You can then save and exit:
control + o // to save to file
control + x // to close the file
$ source ~/.bash_profile
You can then run your zipalign command from your project CLI directory.
if you are making ionic release build then you can make build.json file on your app's root folder with these information given below
{
"android": {
"release": {
"keystore": "Your keystore",
"storePassword": "password",
"alias": "alias name",
"password" : "password",
"keystoreType": ""
}
} }
make sure that you can place your keystore on your app's root folder or provide full path of your keystore at keystore object
now just you can run this command as below
ionic cordova build android --release
this command automatically find your build.json and make signed release build.
Solved!
I copied zipalign file as Michael Said
( from my Library/Android/SDK/build-tools/28.0.3 into my Ionic project folder)
BUT when I run
./zipalign -v 4 app-release-unsigned.apk botellamovil.apk
I got
./zipalign: ERROR while loading shared libraries: libc++.so: cannot open shared object file: **No such file or directory**
So, I also copied lib & lib64 files, and then it Works!!
I hope it will be helpful :) (and sorry for my English)
You should do (align, sign, and verify)for APK.
In mac, you should do the following steps:
A - Aligning APK:
1- you should locate zipalign your build tools inside android SDK:
/Users/mina/Downloads/sdk/build-tools/29.0.3/zipalign
2- you should locate your unsigned apk:
/Users/mina/Desktop/apks/app_unsigned.apk
3- you should run command contains:
zipalign_path + -v -p 4 + unsigned_apk_path + output_aligned_apk_name
/Users/mina/Downloads/sdk/build-tools/29.0.3/zipalign -v -p 4
/Users/mina/Desktop/apks/app-unsigned.apk app_aligned.apk
4- output is Verification successful
B - Signing APK:
1- you should locate apksigner your build tools inside android SDK:
/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner
2- you should locate your release-Keystore in your pc:
/Users/mina/Desktop/keys/release-Keystore.jks
3- you should run command contains:
apksigner_path + sign --ks + release-Keystore_path + --out + output_signed_apk_name + from_aligned_apk_name
/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner sign --ks
/Users/mina/Desktop/keys/release-keystore.jks
--out app_signed.apk app_aligned.apk
4- enter your key store password
C- Verifying APK:
1- run the following command : apksigner_path + verify + app_signed.apk
/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner verify
app_signed.apk
Notes: you may find some warnings:
WARNING: META-INF/....
Here is some description about that:
Apk Metainfo Warning
In practice, these files are not important, they're mostly versions of libraries you depend on, so even if someone modified those, it wouldn't have any impact on your app. That's why it's only a warning: those files in your APK can be modified by someone else while still pretending that the APK is signed by you, but those files don't really matter.
D- find your signed APK:
/Users/mina/app_signed.apk
I solved this problem by making the zipalign path an environment variable:
export ZIPALIGN_PATH=~/Library/Android/sdk/build-tools/30.0.3/zipalign
Then I replaced zipalign with $ZIPALIGN_PATH in the script I was trying to run
I'm running into several problems since I installed Kali from the USB live installer.
I found out that I needed to add this into my sources.list file in /etc/apt folder.
Just replace the content of sources.list with:
deb http://http.kali.org/kali kali-rolling main contrib non-free
deb-src http://http.kali.org/kali kali-rolling main contrib non-free
deb http://old.kali.org/kali sana main non-free contrib
deb http://ftp.de.debian.org/debian wheezy main
I found this link https://stackoverflow.com/questions/6579697/android-how-to-make-the-versioncode-update-automatically-with-every-build that contains the following code:
#!/usr/bin/env bash
MANIFEST="AndroidManifest.xml"
if [ -f $MANIFEST ]
then
LINE=$(grep -o ${MANIFEST} -e 'android:versionCode="[0-9]*"');
declare -a LINE;
LINE=(`echo $LINE | tr "\"" " "`);
VERSION=(${LINE[1]});
INCREMENTED=$(($VERSION+1))
sed "s/android:versionCode=\"[0-9]*\"/android:versionCode=\"${INCREMENTED}\"/" $MANIFEST > $MANIFEST.tmp && mv $MANIFEST.tmp $MANIFEST
git add $MANIFEST
echo "Updated android:versionCode to ${INCREMENTED} in ${MANIFEST}";
fi
I'm using a TortoiseSVN with a windows SVN server however (VisualSVN) so I'm wondering if this could be put into a cygwin command somehow so that the pre-commit hooks in svn can run this? I've not used cygwin much, but am looking for a way to have my version name update every time a commit is built.
Edit: actually it looks like you can use a tool call FARThttp://fart-it.sourceforge.net/ to find and replace text, so i may be able to write a batch script in the SVN pre-commit to find and replace the text.
Edit #2: FART would be more complicated, I'm going to try using the first script, but replace "git add" with "svn add" and see if that works
You can use Maven (which supports Android development) with buildnumber plugin.
It let's you create build numbers via an SCM, via a sequential build number, or via a timestamp. See usage page.
In the same post you mentioned, I posted a different solution, because SVN boldly recommends not changing the commit content with a pre-commit hook , you can make it all go corrupt!
Your manifest can keep the same versionCode forever in svn, instead you should change /bin/AndroidManifest.xml , that is the one which will be packaged in the .apk file