1. Create cordova applications

Initialize the Cordova application. If the application already exists, skip this step

Cordvoa create cordova - the aar com. Chinacreator. App. The demo integrated demo cordova platform add android cordova build androidCopy the code

Package the Lib of Cordova as an AAR

  • Import the generated application into Android Studio

  • The AAR that generates CordovaLib

  • Copy and save this file

Package Cordova apps as AArs

  • Modified. / app/build. Gradle
// apply plugin: 'com.android.application' apply plugin: 'com.android.library' // change to library...... / / applicationId privateHelpers. ExtractStringFromManifest (" package ") / / comment ID applicationCopy the code
  • Modified. / app/SRC/main/AndroidManifest. XML
<application android:hardwareAccelerated="true" android:supportsRtl="true">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
    </activity>
</application>
Copy the code
  • Generate an AAR for the APP

  • Copy save application AAR

4. Native APP integration with Cordova

  • Copy the generated AAR resources to the native application

  • Import the AAR package
. android { ...... // AAR repository {flatDir {dirs 'libs'}} dependencies {...... compile(name: 'CordovaLib-release', ext: 'aar') compile(name: 'app-release', ext: 'aar') }Copy the code
  • Start the Activity of the Cordova application
startActivity(new Intent(this, com.chinacreator.app.demo.MainActivity.class));
Copy the code