包 androidx.core.content 不存在
Posted
技术标签:
【中文标题】包 androidx.core.content 不存在【英文标题】:package androidx.core.content does not exist 【发布时间】:2022-01-16 16:22:06 【问题描述】:我正在尝试使用以下命令在 android 上运行 Ionic 5 应用程序
ionic cap run android -l --external --verbose
但出现这些错误
> Task :capacitor-cordova-android-plugins:compileDebugJavaWithJavac FAILED
[capacitor] C:\xxx\android\capacitor-cordova-android-plugins\src\main\java\de\appplant\cordova\emailcomposer\Provider.java:22: error: package androidx.core.content does not exist
[capacitor] import androidx.core.content.FileProvider;
[capacitor] ^
[capacitor] C:\xxx\android\capacitor-cordova-android-plugins\src\main\java\de\appplant\cordova\emailcomposer\Provider.java:24: error: cannot find symbol
[capacitor] public class Provider extends FileProvider
[capacitor] ^
[capacitor] symbol: class FileProvider
[capacitor] C:\xxx\android\capacitor-cordova-android-plugins\src\main\java\com\pdf\generator\PDFGenerator.java:68: error: cannot access androidx.appcompat.app.AppCompatActivity
[capacitor] final Context ctx = this.cordova.getActivity().getApplicationContext();
[capacitor] ^
[capacitor] class file for androidx.appcompat.app.AppCompatActivity not found
[capacitor] C:\xxx\android\capacitor-cordova-android-plugins\src\main\java\de\appplant\cordova\emailcomposer\EmailComposer.java:109: error: incompatible types: androidx.appcompat.app.AppCompatActivity cannot be converted
to android.content.Context
[capacitor] return cordova.getActivity();
[capacitor] ^
[capacitor] C:\xxx\android\capacitor-cordova-android-plugins\src\main\java\de\appplant\cordova\emailcomposer\AssetUtil.java:276: error: cannot find symbol
[capacitor] return Provider.getUriForFile(ctx, authority, file);
[capacitor] ^
[capacitor] symbol: method getUriForFile(android.content.Context,java.lang.String,java.io.File)
[capacitor] location: class de.appplant.cordova.emailcomposer.Provider
[capacitor] Note: Some input files use or override a deprecated API.
[capacitor] Note: Recompile with -Xlint:deprecation for details.
[capacitor] 5 errors
[capacitor]
[capacitor] > Task :app:mergeDebugJavaResource
[capacitor] > Task :app:processDebugResources
[capacitor]
[capacitor] FAILURE: Build failed with an exception.
[capacitor]
[capacitor] * What went wrong:
[capacitor] Execution failed for task ':capacitor-cordova-android-plugins:compileDebugJavaWithJavac'.
[capacitor] > Compilation failed; see the compiler error output for details.
[capacitor]
[capacitor] * Try:
[capacitor]
[capacitor] Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
[capacitor] Use '--warning-mode all' to show the individual deprecation warnings.
[capacitor] See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings
[capacitor] 152 actionable tasks: 42 executed, 110 up-to-date
[capacitor] 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.
[capacitor]
[capacitor] * Get more help at https://help.gradle.org
[capacitor]
[capacitor] BUILD FAILED in 45s
[capacitor]
[capacitor] C:\xxx\android>if "1" == "0" goto mainEnd
[capacitor]
[capacitor] C:\xxx\android>rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
[capacitor]
[capacitor] C:\xxx\android>rem the _cmd.exe /c_ return code!
[capacitor]
[capacitor] C:\xxx\android>if not "" == "" exit 1
[capacitor]
[capacitor] C:\xxx\android>exit /b 1
[capacitor]
[ERROR] An error occurred while running subprocess capacitor.
capacitor.cmd run android --no-sync --target ce01182192619a1301 exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 6 functions +0ms
ionic:lib:hooks Looking for ionic:serve:after npm script. +54s
ionic:utils-process error while killing process tree for 5752: Error: Command failed: taskkill /pid 5752 /T /F
ionic:utils-process ERROR: The process "5752" not found.
ionic:utils-process
ionic:utils-process at ChildProcess.exithandler (child_process.js:308:12)
ionic:utils-process at ChildProcess.emit (events.js:315:20)
ionic:utils-process at maybeClose (internal/child_process.js:1048:16)
ionic:utils-process at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
ionic:utils-process killed: false,
ionic:utils-process code: 128,
ionic:utils-process signal: null,
ionic:utils-process cmd: 'taskkill /pid 5752 /T /F'
过去三天我一直在努力寻找解决方案,但没有成功。我已经做了以下修复它,但它仍然显示同样的错误
在 gradle.properties 中
android.useAndroidX=true
android.enableJetifier=true
在 variables.gradle 中
minSdkVersion = 23
compileSdkVersion = 30
targetSdkVersion = 26
androidxActivityVersion = '1.2.0'
androidxAppCompatVersion = '1.2.0'
androidxCoordinatorLayoutVersion = '1.1.0'
androidxCoreVersion = '1.3.2'
androidxFragmentVersion = '1.3.0'
junitVersion = '4.13.1'
androidxJunitVersion = '1.1.2'
androidxEspressoCoreVersion = '3.3.0'
cordovaAndroidVersion = '10.1.1'
在 build.gradle 中
repositories
google()
mavenCentral()
...
...
allprojects
repositories
google()
mavenCentral()
这些更改都不能解决问题。但是,如果我在 Android Studio 中打开 android build
ionic cap open android
并将库“Gradle:androidx.core:core:1.3.0@aar”作为智能感知建议添加到类路径中,然后它可以工作,我可以从 Android Studio 在设备上运行该项目。 但是,如果我进行更改并重建,那么它会再次显示相同的错误。
环境细节
Ionic:
Ionic CLI : 6.16.3 (C:\Users\xxx\AppData\Roaming\npm\node_modules\@ionic\cli)
Ionic Framework : @ionic/angular 5.6.11
@angular-devkit/build-angular : 12.0.5
@angular-devkit/schematics : 12.0.5
@angular/cli : 12.0.5
@ionic/angular-toolkit : 4.0.0
Capacitor:
Capacitor CLI : 3.1.1
@capacitor/android : 3.3.2
@capacitor/core : 3.3.2
@capacitor/ios : not installed
Utility:
cordova-res : 0.15.3
native-run : 1.4.0
System:
NodeJS : v14.16.0 (C:\Program Files\nodejs\node.exe)
npm : 6.14.11
OS : Windows 10
请为此提出任何解决方案。
非常感谢
【问题讨论】:
您找到解决方案了吗?如果是,请告诉。 不,还没有找到解决办法。目前已删除导致此问题的电子邮件撰写器模块 【参考方案1】:尝试以下步骤:
ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter
如果仍然无法正常工作,请尝试步骤:
npm install jetifier
npx jetifier
npx cap sync android
【讨论】:
已经做了这些 @Bhavesh 您使用的是什么版本的 JAVA?尝试将 java 更新到最新版本 添加了有问题的环境细节【参考方案2】:如果您使用的是 Capacitor,则不能像在 Cordova 中那样“添加插件”...
你必须从 npm 或 yarn 安装它。
npm i cordova-plugin-androidx
npm i cordova-plugin-androidx-adapter....
或者尝试更新到最新的 Capacitor、Ionic 和 Android Studio。
【讨论】:
已尝试从 npm 安装插件并更新 ionic 但仍然出现同样的错误。这就是我所拥有的 Ionic CLI 6.16.2 Ionic Framework: 5.6.11 Angular: 12.0.5 Capacitor CLI: 3.1.1 Capacitor Core: 3.3.1 已添加有关问题的全部细节以上是关于包 androidx.core.content 不存在的主要内容,如果未能解决你的问题,请参考以下文章
Android报错: exposed beyond app through Intent.getData()