Up until recently I have been using the following
- Cordova Android 6.3.0
- Gradle 4.9
- Node 8.9.2
to build my hybrid Android app which uses one custom - i.e. written by me - plugin. The plugin in turn has a number of external dependencies which I specify via the myapp/platforms/android/build-extras.gradle file which is listed below
ext.postBuildExtras =
{
android
{
dependencies
{
compile 'com.squareup.duktape:duktape-android:1.3.0'
compile 'net.zetetic:android-database-sqlcipher:3.5.9@aar'
compile 'co.realtime:messaging-android:2.1.+'
compile 'com.google.android.gms:play-services-location:15.0.1'
compile 'com.android.installreferrer:installreferrer:1.0'
}
defaultConfig
{
jackOptions {enabled true}
}
compileOptions
{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
allprojects
{
compileOptions
{
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
}
}
I target Android SDK 26 with the minimum SDK level set at 23. My Cordova config.xml
file is shown below
<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="1190" android-versionName="Etoile-2"
id="my.app.id" version="1.1.9" xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>My App</name>
<description>My App</description>
<author email="[email protected]" href="https://example.org">My Name.
</author>
<content src="index.html" />
<access origin="*" />
<icon platform="android" qualifier="mdpi" src="res/mdpi.png" />
<icon platform="android" qualifier="hdpi" src="res/hdpi.png" />
<icon platform="android" qualifier="xhdpi" src="res/xhdpi.png" />
<icon platform="android" qualifier="xxdpi" src="res/xxdpi.png" />
<icon platform="android" qualifier="xxxdpi" src="res/xxxdpi.png" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
<FrameLayout android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
</FrameLayout>
<preference name="android-minSdkVersion" value="23" />
<preference name="android-targetSdkVersion" value="26" />
</platform>
<preference name="Orientation" value="portrait" />
<plugin name="ext.org.plugin" spec="path:\to\my\plugin" />
<engine name="android" spec="^7.0.0" />
</widget>
I am in the process of provisioning a more modern Windows PC to do my Android builds. In the process I have upgraded to
- Cordova Android 7.0.0
- Gradle 4.10.0 (installed via Scoop)
- Node 10.10.0
I went through the process of reconstructing the entire project step-by-step
- Create a new Cordova CLI project
cordova create myapp ext.example.myproj MyApp
- Add the Android platform
cordova platform add android
which adds Cordova Android 7.0.0 - Build this dummy app
cordova build android --debug
: working - Replace the default Cordova
config.xml
with my version (shown above) minus the reference to my custom plugin - Build again - still working
- Copy across my original
build-extras.gradle
file to myapp/platforms/android - Build again - still working
- Add my custom plugin
cordova plugin add 'path:\to\my\plugin
Issue a
cordova clean
followed bycordova build android
which results in errors along the lines of:app:compileDebugJavaWithJavac path:\to\my\app\platforms\android\app\src\main\java\ext\example\plugin\BCTrailer.java:4: error: package net.sqlcipher does not exist import net.sqlcipher.Cursor;
which appears to imply that the contents of my build-extras.gradle
file were not used during the build. I deliberately corrupted that file by leaving out a brace to make the XML invalid. If the file were being read I had expected that Gradle would complain. Instead it just goes ahead and issues the same errors such as package net.sqlcipher
does not exist etc.
I have noted talk of compile
being deprecated in dependencies in favor of a whole new clutch of instructions such as implementation
and api
. I tried replacing compile
with implementation
in my own build-extras.gradle
file but to no avail.
Clearly, I am doing something wrong here and it has to do with the changes in Gradle.
Whilst I still do not understand the root cause of the problems I ran into during my attempt at upgrading the Android APK build toolchain I now have a solution which I am sharing here for the benefit of others who find this thread.
build-extras.gradle
in themyapp/platforms/android
folder is being ignored.build-extras
file in the APK project itself.build-extras.gradle
**ext.postBuildExtras**
were working to fork in external dependencies in a plugin which one would assume had been built in to the app by that point.build.gradle
file in the actual plugin. However, this did not change the outcome - the dependencies did not make it into the build with the result that variousimport path.to.external.dependency
declarations in Java units in the plugin threw errors.build.gradle
file and declared the dependencies via a series of<framework src='path/to/dependency' />
dependency statements in theplugin.xml
file and Bingo! - it all worked.As a side note - with Cordova Android 7 and anything higher than Node 9.0 you no longer need to use the, now deprecated, Jack compiler or do anything else to persuade Gradle/Android/Cordova to use Java 8. I am now no longer using a
build-extras.gradle
file in my app or abuild.gradle
file in my plugin.