Native platform Code in a PhoneGap / Cordova Project

Suppose there is a PhoneGap / Cordova project named “AppDemo” with added platforms as Android and iOS. 

Android

Open a PhoneGap / Cordova project in Android Studio

– Open the project’s pom.xml file from the location <projectlocation>/AppDemo/platforms/android/pom.xml in the Android Studio.

– assets folder contains the www folder which has the platform-level web technology code [HTML, CSS, JS]. Any changes made in this folder at this level, changes only the android platform but not the entire project irrespective of the platform.

– src folder contains most of the native android code for the project which is created automatically by Cordova

Build and Run

– In the terminal / command prompt, do the following

$ cd <projectlocation>/AppDemo/platforms/android/AppDemo/scripts

 $ copywww.sh

This updates the entire changes made on the higher level www folder to the android platform.

– Now open the Android Studio, Delete the existing project and reopen this new project.

– Clean Build the project.

– Now Run the android app.

iOS

To open the native iOS content of the project in XCode, do the following-

– Open the project’s .xcodeproj file from the location <projectlocation>/AppDemo/platforms/ios/AppDemo.xcodeproj in the XCode.

– Stagging folder contains the www folder which has the platform-level web technology code [HTML, CSS, JS, etc].Any changes made in this folder at this level, changes only the iOS platform but not the entire project irrespective of the platform.

– Classes folder contains some part of the native iOS code for the project which is created automatically by Cordova

Build and Run

– iOS automatically updates the changes made in the higher level www folder to iOS specific www folder.

– To Clean Build the project, Option Key + (Product -> Clean Build Folder)

– Now Run the iOS app.

Note

– In order to make changes to both the platforms, make sure the changes are made in the higher level www folder instead of the platform level www folder.

– It is important to clean build and run the project after any changes made in the higher level www folder.

Previous
Previous

Resolve “Manifest Merger Failed” on Android 12

Next
Next

Interview Questions (2/2): PhoneGap & Cordova (Copy)