Up until recently I have been using the following
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="someone@gmail.com" 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
I went through the process of reconstructing the entire project step-by-step
cordova create myapp ext.example.myproj MyApp
cordova platform add android
which adds Cordova Android 7.0.0cordova build android --debug
: workingconfig.xml
with my version (shown above) minus the reference to my custom pluginbuild-extras.gradle
file to myapp/platforms/androidcordova plugin add 'path:\to\my\plugin
Issue a cordova clean
followed by cordova 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 the myapp/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 various import 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 the plugin.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 a build.gradle
file in my plugin.