我正在嘗試使用以下命令在 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
請為此提出任何解決方案。
非常感謝
uj5u.com熱心網友回復:
試試這些步驟:
ionic cordova plugin add cordova-plugin-androidxionic cordova plugin add cordova-plugin-androidx-adapter
如果仍然無法正常作業,請嘗試步驟:
npm install jetifier
npx jetifier
npx cap sync android
uj5u.com熱心網友回復:
如果您使用的是電容器,則無法像在 Cordova 中那樣“添加插件”...
你必須從 npm 或 yarn 安裝它。
npm i cordova-plugin-androidx npm i cordova-plugin-androidx-adapter....
或者嘗試更新到最新的 Capacitor、Ionic 和 Android Studio
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/386875.html
上一篇:如何安裝離子電容接觸原生插件
