I want to generate an apk for my Ionic-React app, only using the command-line.
I am able to use Ionic Capacitor to make an apk via Android-Studio, but I want to purely use the CLI to generate the same apk.
Cordova does not work for Ionic-React projects, otherwise I would use that.
Is this possible to do? Thanks.
Just a quick look learns that the react build process does not build the things needed for a cordova project.
The index.html does not have reference to cordova.js and the assets are in the public folder, not www.
I am not a react dev, but if you create a new cordova project using the cordova create command in a new folder, then you can see the difference between two index.html
There are multiple ways to get around this. For instance copy the public assets of the react project in the www folder of the empty cordova project, but then you also need to compare index.html.
Or other way around, but then you need to compare all other files in cordova with your react project, including copying config.xml, changing package.json probably etc. in order for cordova to recognise the project as a genuine cordova project.
I would try the first with a simple copy command transferring all react assets to the cordova project and changing the index.html in the react project to have the includes of the js scripts. Won’t hurt in dev.
Then you should be able to use cordova platform add to make the necessary steps into apk.
I have, and have come across a sticking point - I run ionic build & ionic capacitor add android. This creates and android folder which I cd into. From here I try to run ./ gradlew build and this doesn’t work - however if I open the project with android studio and run the same command, it does work.
I think this is because it seems like android studio creates a few files the first time it opens your project, such as the local.properties file. Without this running ./ gradlew build fails. If you have any idea of how to get aorund this that would be great.
Thanks for the detailed reply, unfortunately I was hoping for something more automated than copying over files and changing certain file contents.
Appreciate you taking the time to write it though