[英]Cordova CLI project ignores build-extras after toolchain upgrade
直到最近我一直在使用以下
构建我的混合 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 构建。 在这个过程中我已经升级到
我一步步完成了整个项目的重构过程
cordova create myapp ext.example.myproj MyApp
cordova platform add android
其中添加Cordova Android 7.0.0cordova build android --debug
:workingconfig.xml
减去对我的自定义插件的引用build-extras.gradle
文件复制到 myapp/platforms/androidcordova plugin add 'path:\\to\\my\\plugin
发出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
以支持全新的指令集,例如implementation
和api
。 我尝试在我自己的build-extras.gradle
文件中用implementation
替换compile
但无济于事。
显然,我在这里做错了,这与 Gradle 中的变化有关。
在cordova-android 7.1.3 中,我的pull request 被包含在内,因此问题已解决,请参阅发行说明
将build-extras.gradle
移动(或复制)到platforms/android/app/
我有一个类似的问题。 从 cordova-android 7.0 开始,cordova 更改了目录结构并错过了那里代码中的一些更改。
要让build-extras.gradle
再次工作,只需将其移动或更好地将其复制(当 cordova-android 再次遵循他们的文档时)到platforms/android/app/
。
虽然我仍然不明白我在尝试升级 Android APK 构建工具链时遇到的问题的根本原因,但我现在有一个解决方案,我在此分享,以供发现此线程的其他人受益。
myapp/platforms/android
文件夹中的build-extras.gradle
被忽略。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.