[英]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 - 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
在这个过程中我已经升级到
I went through the process of reconstructing the entire project step-by-step我一步步完成了整个项目的重构过程
cordova create myapp ext.example.myproj MyApp
cordova create myapp ext.example.myproj MyApp
cordova platform add android
which adds Cordova Android 7.0.0cordova platform add android
其中添加Cordova Android 7.0.0cordova build android --debug
: workingcordova build android --debug
:workingconfig.xml
with my version (shown above) minus the reference to my custom pluginconfig.xml
减去对我的自定义插件的引用build-extras.gradle
file to myapp/platforms/androidbuild-extras.gradle
文件复制到 myapp/platforms/androidcordova plugin add 'path:\\to\\my\\plugin
cordova plugin add 'path:\\to\\my\\plugin
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
以支持全新的指令集,例如implementation
和api
。 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 中的变化有关。
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 被包含在内,因此问题已解决,请参阅发行说明
Move (or copy) the build-extras.gradle
to platforms/android/app/
将
build-extras.gradle
移动(或复制)到platforms/android/app/
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 构建工具链时遇到的问题的根本原因,但我现在有一个解决方案,我在此分享,以供发现此线程的其他人受益。
build-extras.gradle
in the myapp/platforms/android
folder is being ignored.myapp/platforms/android
文件夹中的build-extras.gradle
被忽略。build-extras
file in the APK project itself.build-extras
文件开始声明插件依赖项都是不正确的。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**
正在努力在插件中分叉外部依赖项,人们认为它具有到那时已内置到应用程序中。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.import path.to.external.dependency
声明抛出错误。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.