Android installLocation when building with cordova cli

926 Views Asked by At

I am building a large cordova/phonegap app using the cordova CLI tools. I need the installLocation in the AndroidManifest.xml file to have the installLocation="auto" (or preferExternal) setting. I have tried placing <preference name="android-installLocation" value="auto" /> in my config.xml file. However, I think that preference might only be valid when building with phonegap, not cordova.

Is there a way to get this preference automatically added to the AndroidManifest.xml when building with the Cordova CLI tools?

3

There are 3 best solutions below

0
On

This plugin does exactly what you need: https://github.com/dpa99c/cordova-custom-config.

It extends the default capabilities of cordova-cli to patch the platform specific files on iOS and Android. Of course, these extra configuration options might be overridden by future versions of cordova, but for now it does the job.

0
On

For future reference:

In your config.xml, inside the <platform name="android"> tag, enter the following lines:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest">
    <manifest android:installLocation="auto" />
</edit-config>

Explanation:

  • The tag edit-config is used to modify XML-based configuration files (in this case - app/src/main/AndroidManifest.xml).
  • To target the manifest tag, we use the XML attribute target="/manifest".
  • Using the XML attribute mode="merge", we then merge our own required XML Element with it (in this case - <manifest android:installLocation="auto" />).

Details about cordova edit-config here.

Details about android install location here.

0
On

Use cordova plugin : https://github.com/dpa99c/cordova-custom-config

Add following in config.xml :

Inside <platform name="android">

<custom-preference name="android-manifest/@android:installLocation" value="auto" />