繁体   English   中英

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

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

直到最近我一直在使用以下

  • 科尔多瓦安卓 6.3.0
  • 摇篮 4.9
    • 节点 8.9.2

构建我的混合 Android 应用程序,该应用程序使用一个自定义(即由我编写)插件。 该插件又具有许多我通过下面列出的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
   }
  }
 }
}

我的目标是 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>

我正在配置一台更现代的 Windows PC 来完成我的 Android 构建。 在这个过程中我已经升级到

  • 科尔多瓦安卓 7.0.0
  • Gradle 4.10.0(通过 Scoop 安装)
  • 节点 10.10.0

我一步步完成了整个项目的重构过程

  1. 创建一个新的 Cordova CLI 项目cordova create myapp ext.example.myproj MyApp
  2. 添加Android平台cordova platform add android其中添加Cordova Android 7.0.0
  3. 构建这个虚拟应用程序cordova build android --debug :working
  4. 用我的版本(如上所示)替换默认的 Cordova config.xml减去对我的自定义插件的引用
  5. 再次构建 - 仍在工作
  6. 将我原来的build-extras.gradle文件复制到 myapp/platforms/android
  7. 再次构建 - 仍在工作
  8. 添加我的自定义插件cordova plugin add 'path:\\to\\my\\plugin
  9. 发出cordova clean然后cordova build android这会导致错误

    :app:compileDebugJavaWithJavac path:\\to\\my\\app\\platforms\\android\\app\\src\\main\\java\\ext\\example\\plugin\\BCTrailer.java:4: 错误:包 net.sqlcipher 不存在 import net.sqlcipher 。光标;

这似乎暗示我的build-extras.gradle文件的内容在build-extras.gradle过程中没有被使用。 我故意通过省略大括号使 XML 无效来损坏该文件。 如果正在读取文件,我原以为 Gradle 会抱怨。 相反,它只是继续并发出相同的错误,例如package net.sqlcipher不存在等。

我已经注意到在依赖项中不推荐使用compile以支持全新的指令集,例如implementationapi 我尝试在我自己的build-extras.gradle文件中用implementation替换compile但无济于事。

显然,我在这里做错了,这与 Gradle 中的变化有关。

更新:在cordova-android 7.1.3 中修复

在cordova-android 7.1.3 中,我的pull request 被包含在内,因此问题已解决,请参阅发行说明

对于cordova-android >= 7.0.0 但< 7.1.3

build-extras.gradle移动(或复制)到platforms/android/app/

旧答案:

我有一个类似的问题。 从 cordova-android 7.0 开始,cordova 更改了目录结构并错过了那里代码中的一些更改。

要让build-extras.gradle再次工作,只需将其移动或更好地将其复制(当 cordova-android 再次遵循他们的文档时)到platforms/android/app/

这是问题,这是相关的拉取请求

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

  • 使用 Cordova Android 7.0.0(与我之前使用的 6.3.1 相反) myapp/platforms/android文件夹中的build-extras.gradle被忽略。
  • 在任何情况下,通过 APK 项目本身中的build-extras文件开始声明插件依赖项都是不正确的。
  • 尽管在此工具链升级之前这一直对我build-extras.gradle ,但我发现在build-extras.gradle **ext.postBuildExtras**中声明的依赖**ext.postBuildExtras**正在努力在插件中分叉外部依赖项,人们认为它具有到那时已内置到应用程序中。
  • 我尝试将我的依赖项声明切换到实际插件中build.gradle文件。 但是,这并没有改变结果 - 依赖项没有进入构建,结果是插件中 Java 单元中的各种import path.to.external.dependency声明抛出错误。
  • 我除去build.gradle文件并通过一系列声明的依赖性<framework src='path/to/dependency' />依赖性在语句plugin.xml文件和宾果! - 一切都奏效了。

附带说明 - 使用 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