我正在使用Cordova插件在电容器离子项目中使用fileOpener。在此之前,当我安装以下软件包时,一切都很好:
npm install @ionic-native/file
npm install cordova-plugin-file
npm install @ionic-native/file-opener
npm install cordova-plugin-file-opener2
这是我面临的错误:
> Configure project :
The RepositoryHandler.jcenter() method has been deprecated. This is scheduled to be removed in Gradle 8.0. JFrog announced JCenter's sunset in
February 2021. Use mavenCentral() instead. Consult the upgrading guide for further information: https://docs.gradle.org/7.4/userguide/upgrading_version_6.html#jcenter_deprecation
at build_dcpio6s66acap9ob7gfqiirhb$_run_closure1$_closure2.doCall(C:ProjectIonicmock-serviceandroidbuild.gradle:7)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
WARNING:: Using flatDirs should be avoided because it doesn't support any meta-data formats.
Currently detected usages:
- repository flatDir used in: project ':app', project ':capacitor-cordova-android-plugins'
WARNING:: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
This repository is deprecated and it will be shut down in the future.
See http://developer.android.com/r/tools/jcenter-end-of-service for more information.
Currently detected usages in: root project 'android', project ':app', project ':capacitor-android', ...
> Task :capacitor-android:compileDebugAidl NO-SOURCE
Relying on FileTrees for ignoring empty directories when using @SkipWhenEmpty has been deprecated. This is scheduled to be removed in Gradle 8.0. Annotate the property sourceFiles with @IgnoreEmptyDirectories or remove @SkipWhenEmpty. Consult the upgrading guide for further information: https://docs.gradle.org/7.4/userguide/upgrading_version_7.html#empty_directories_file_tree
> Task :app:compileDebugRenderscript NO-SOURCE
Relying on FileTrees for ignoring empty directories when using @SkipWhenEmpty has been deprecated. This is scheduled to be removed in Gradle 8.0. Annotate the property sourceDirs with @IgnoreEmptyDirectories or remove @SkipWhenEmpty. Consult the upgrading guide for further information: https://docs.gradle.org/7.4/userguide/upgrading_version_7.html#empty_directories_file_tree
> Task :capacitor-cordova-android-plugins:compileDebugJavaWithJavac FAILED
C:ProjectIonicmock-serviceandroidcapacitor-cordova-android-pluginssrcmainjavaiogithubpwlincordovapluginsfileopener2FileProvider.java:28: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {
^
C:ProjectIonicmock-serviceandroidcapacitor-cordova-android-pluginssrcmainjavaiogithubpwlincordovapluginsfileopener2FileOpener2.java:119: error: cannot find symbol
path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".fileOpener2.provider", file);
^
symbol: method getUriForFile(android.content.Context,java.lang.String,java.io.File)
location: class io.github.pwlin.cordova.plugins.fileopener2.FileProvider
C:ProjectIonicmock-serviceandroidcapacitor-cordova-android-pluginssrcmainjavaiogithubpwlincordovapluginsfileopener2FileOpener2.java:127: error: cannot find symbol
Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".fileOpener2.provider", file);
^
symbol: method getUriForFile(android.content.Context,java.lang.String,java.io.File)
location: class io.github.pwlin.cordova.plugins.fileopener2.FileProvider
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:ProjectIonicmock-serviceandroidcapacitor-cordova-android-pluginssrcmainjavaorgapachecordovafileAssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':capacitor-cordova-android-plugins:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
70 actionable tasks: 1 executed, 69 up-to-date
Package.json:
"dependencies": {
"@angular/common": "~13.0.0",
"@angular/core": "~13.0.0",
"@angular/forms": "~13.0.0",
"@angular/platform-browser": "~13.0.0",
"@angular/platform-browser-dynamic": "~13.0.0",
"@angular/router": "~13.0.0",
"@capacitor/android": "3.4.1",
"@capacitor/app": "1.1.0",
"@capacitor/core": "3.4.1",
"@capacitor/haptics": "1.1.4",
"@capacitor/keyboard": "1.2.2",
"@capacitor/status-bar": "1.0.8",
"@ionic-native/file": "^5.36.0",
"@ionic-native/file-opener": "^5.36.0",
"@ionic/angular": "^6.0.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-opener2": "^3.0.5",
"rxjs": "~6.6.0",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
},
Java版本:
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) Client VM (build 25.321-b07, mixed mode)
渐变版本:
distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip
我在网上什么都试过了。也许我错过了什么。请帮我解决这个问题。谢谢
清理项目
在android目录中运行gradlew-clean
然后运行以下命令,如果您使用电容器或cordova或ionic js ,它会将您的节点模块包复制并粘贴到android目录中
npx cap同步
重要步骤运行npx jetify
如果没有在您的本地机器上安装jetifynpm安装jetifier
我将cordova插件文件从版本7降级到版本6,它解决了问题!
请参阅详细信息:https://github.com/ionic-team/capacitor/issues/5602
以上答案对我来说都不起作用。最终起作用的是将Android构建工具从v9降级到v5。