androidcordovagradlecordova-cli

Cordova CLI project ignores build-extras after toolchain upgrade


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

  1. Create a new Cordova CLI project cordova create myapp ext.example.myproj MyApp
  2. Add the Android platform cordova platform add android which adds Cordova Android 7.0.0
  3. Build this dummy app cordova build android --debug: working
  4. Replace the default Cordova config.xml with my version (shown above) minus the reference to my custom plugin
  5. Build again - still working
  6. Copy across my original build-extras.gradle file to myapp/platforms/android
  7. Build again - still working
  8. Add my custom plugin cordova plugin add 'path:\to\my\plugin
  9. 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.


Solution

  • 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.

    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.