简体   繁体   English

Cordova CLI 项目在工具链升级后忽略 build-extras

[英]Cordova CLI project ignores build-extras after toolchain upgrade

Up until recently I have been using the following直到最近我一直在使用以下

  • Cordova Android 6.3.0科尔多瓦安卓 6.3.0
  • Gradle 4.9摇篮 4.9
    • Node 8.9.2节点 8.9.2

to build my hybrid Android app which uses one custom - ie written by me - plugin.构建我的混合 Android 应用程序,该应用程序使用一个自定义(即由我编写)插件。 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该插件又具有许多我通过下面列出的myapp/platforms/android/build-extras.gradle文件指定的外部依赖项

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我的目标是 Android SDK 26,最低 SDK 级别设置为 23。我的 Cordova config.xml文件如下所示

<?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.我正在配置一台更现代的 Windows PC 来完成我的 Android 构建。 In the process I have upgraded to在这个过程中我已经升级到

  • Cordova Android 7.0.0科尔多瓦安卓 7.0.0
  • Gradle 4.10.0 (installed via Scoop) Gradle 4.10.0(通过 Scoop 安装)
  • Node 10.10.0节点 10.10.0

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创建一个新的 Cordova CLI 项目cordova create myapp ext.example.myproj MyApp
  2. Add the Android platform cordova platform add android which adds Cordova Android 7.0.0添加Android平台cordova platform add android其中添加Cordova Android 7.0.0
  3. Build this dummy app cordova build android --debug : working构建这个虚拟应用程序cordova build android --debug :working
  4. Replace the default Cordova config.xml with my version (shown above) minus the reference to my custom plugin用我的版本(如上所示)替换默认的 Cordova config.xml减去对我的自定义插件的引用
  5. Build again - still working再次构建 - 仍在工作
  6. Copy across my original build-extras.gradle file to myapp/platforms/android将我原来的build-extras.gradle文件复制到 myapp/platforms/android
  7. Build again - still working再次构建 - 仍在工作
  8. Add my custom plugin cordova plugin add 'path:\\to\\my\\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发出cordova clean然后cordova build android这会导致错误

    :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; :app:compileDebugJavaWithJavac path:\\to\\my\\app\\platforms\\android\\app\\src\\main\\java\\ext\\example\\plugin\\BCTrailer.java:4: 错误:包 net.sqlcipher 不存在 import net.sqlcipher 。光标;

which appears to imply that the contents of my build-extras.gradle file were not used during the build.这似乎暗示我的build-extras.gradle文件的内容在build-extras.gradle过程中没有被使用。 I deliberately corrupted that file by leaving out a brace to make the XML invalid.我故意通过省略大括号使 XML 无效来损坏该文件。 If the file were being read I had expected that Gradle would complain.如果正在读取文件,我原以为 Gradle 会抱怨。 Instead it just goes ahead and issues the same errors such as package net.sqlcipher does not exist etc.相反,它只是继续并发出相同的错误,例如package net.sqlcipher不存在等。

I have noted talk of compile being deprecated in dependencies in favor of a whole new clutch of instructions such as implementation and api .我已经注意到在依赖项中不推荐使用compile以支持全新的指令集,例如implementationapi I tried replacing compile with implementation in my own build-extras.gradle file but to no avail.我尝试在我自己的build-extras.gradle文件中用implementation替换compile但无济于事。

Clearly, I am doing something wrong here and it has to do with the changes in Gradle.显然,我在这里做错了,这与 Gradle 中的变化有关。

Update: fixed in cordova-android 7.1.3更新:在cordova-android 7.1.3 中修复

In cordova-android 7.1.3 my pull request was included so the issue is fixed see the release notes在cordova-android 7.1.3 中,我的pull request 被包含在内,因此问题已解决,请参阅发行说明

For cordova-android >= 7.0.0 but < 7.1.3对于cordova-android >= 7.0.0 但< 7.1.3

Move (or copy) the build-extras.gradle to platforms/android/app/build-extras.gradle移动(或复制)到platforms/android/app/

Old Answer:旧答案:

I had a similar issue.我有一个类似的问题。 Starting with cordova-android 7.0 cordova changed the directory structure and missed some changes in there code.从 cordova-android 7.0 开始,cordova 更改了目录结构并错过了那里代码中的一些更改。

To get the build-extras.gradle working again just move it or better copy it (when the cordova-android is following their documentation again) to platforms/android/app/ .要让build-extras.gradle再次工作,只需将其移动或更好地将其复制(当 cordova-android 再次遵循他们的文档时)到platforms/android/app/

Here is the issue and here is related pull request这是问题,这是相关的拉取请求

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.虽然我仍然不明白我在尝试升级 Android APK 构建工具链时遇到的问题的根本原因,但我现在有一个解决方案,我在此分享,以供发现此线程的其他人受益。

  • With Cordova Android 7.0.0 (as opposed to 6.3.1 which I was using previously) build-extras.gradle in the myapp/platforms/android folder is being ignored.使用 Cordova Android 7.0.0(与我之前使用的 6.3.1 相反) myapp/platforms/android文件夹中的build-extras.gradle被忽略。
  • It was in any case incorrect to start declaring plugin dependencies via a build-extras file in the APK project itself.在任何情况下,通过 APK 项目本身中的build-extras文件开始声明插件依赖项都是不正确的。
  • Although this had always worked for me prior to this toolchain upgrade I had found it rather strange that dependencies declared in a 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-extras.gradle ,但我发现在build-extras.gradle **ext.postBuildExtras**中声明的依赖**ext.postBuildExtras**正在努力在插件中分叉外部依赖项,人们认为它具有到那时已内置到应用程序中。
  • I tried switching my dependencies declaration to a build.gradle file in the actual plugin .我尝试将我的依赖项声明切换到实际插件中build.gradle文件。 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.但是,这并没有改变结果 - 依赖项没有进入构建,结果是插件中 Java 单元中的各种import path.to.external.dependency声明抛出错误。
  • I removed the 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!我除去build.gradle文件并通过一系列声明的依赖性<framework src='path/to/dependency' />依赖性在语句plugin.xml文件和宾果! - 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.附带说明 - 使用 Cordova Android 7 和任何高于 Node 9.0 的版本,您不再需要使用现已弃用的 Jack 编译器或做任何其他事情来说服 Gradle/Android/Cordova 使用 Java 8。我现在不再使用我的应用程序中的build-extras.gradle文件或插件中的build.gradle文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM