dpa99c / cordova-custom-config

Cordova/Phonegap plugin to update platform configuration files based on preferences and config-file data defined in config.xml
318 stars 84 forks source link

Create two main activities #137

Closed durvilchat closed 6 years ago

durvilchat commented 6 years ago

Hello my friends please i really need your help, i would like to create an app that has two launch icons (two mainActivities this is fine on android studio) and i have a serious problem as cordova does not generates only one MainActivity. If you would like to know how to do it Thank you.

dpa99c commented 6 years ago

You can use this plugin to insert configuration for another activity into your <application> like this:

<custom-config-file target="AndroidManifest.xml" parent="./application">
    <activity android:name="MainActivity2" android:foo="bar" >
            <!-- your activity config -->
    </activity>
</custom-config-file>

So you take the configuration you created in AndroidManifest.xml using Android Studio and use the above as a template.

However, you will still need to write the Java code to implement the activity. This plugin will not help you with that.

dpa99c commented 6 years ago

Closed due to no response from OP

aw-vm commented 6 years ago

Hello, I'm trying to add an activity to the manifest as well but when i try: <custom-config-file target="AndroidManifest.xml" parent="/application"> I'm getting this error: Error: Unable to graft xml at selector "/application" from "/platforms/android/AndroidManifest.xml" during config install And when i check the manifest file it has the activity i wanted to add but outside the application tag.

dpa99c commented 6 years ago

@valerymadiedo Apologies there was a typo in my example above: it should be parent="./application" - not parent="/application" i.e. is should start with .

aw-vm commented 6 years ago

@dpa99c Thank you for your quick response. Also I tried with ./ in this code inside the android platform tag:

<custom-config-file mode="add" parent="./manifest/application" target="AndroidManifest.xml">
            <activity android:launchMode="singleInstance" android:name="NewActivity" />
</custom-config-file>

But now i get this error:

error: Error parsing XML: unbound prefix
* What went wrong:
Execution failed for task ':processDebugResources'.
com.android.ide.common.process.ProcessException: Failed to execute aapt
dpa99c commented 6 years ago

@valerymadiedo you added manifest into the XPath which is incorrect; it should be:

<custom-config-file mode="add" parent="./application" target="AndroidManifest.xml">
    <activity android:launchMode="singleInstance" android:name="NewActivity" />
</custom-config-file>

See the documentation for example usage.

aw-vm commented 6 years ago

Thank you, now it works.

dpa99c commented 6 years ago

@valerymadiedo Check your config.xml for unclosed tags or attributes. You can validate the XML here: https://www.xmlvalidation.com/

aw-vm commented 6 years ago

In my case the xmlns:android="http://schemas.android.com/apk/res/android"was missing from the widget tag. Thank you a lot for your help.