Ionic + Fastlane | Android "error: package android.support.v4.content does not exist"
Ionic + Fastlane | Android "error: package android.support.v4.content does not exist"
我有一个正在使用的 Ionic 项目,在构建 Android 时遇到问题。我继承了这个项目,所以这就是为什么我不是 100% 熟悉 Fastlane 以及它如何构建 java 文件。此外,我在 WSL2 上使用 sdkmanager 和以下已安装的软件包:
Installed packages:=====================] 100% Fetch remote repository...
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;29.0.2 | 29.0.2 | Android SDK Build-Tools 29.0.2 | build-tools/29.0.2
emulator | 30.8.4 | Android Emulator | emulator
patcher;v4 | 1 | SDK Patch Applier v4 | patcher/v4
platform-tools | 31.0.3 | Android SDK Platform-Tools | platform-tools
platforms;android-29 | 5 | Android SDK Platform 29 | platforms/android-29
当我 运行 bundle exec fastlane android build
它做了很多魔术,但最终导致以下错误:
> Task :app:compileReleaseJavaWithJavac FAILED
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:42: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
^
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/FileProvider.java:21: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {}
^
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:297: error: cannot find symbol
this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
^
symbol: method getUriForFile(Activity,String,File)
location: class FileProvider
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:824: error: cannot find symbol
Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
^
symbol: method getUriForFile(Activity,String,File)
location: class FileProvider
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
我看到一些关于使用 androidx.core.content.FileProvider
而不是 android.support.v4.content.FileProvider
的较新 SDK 版本的想法。由于整个 Android 部分是自动构建/生成的,我显然无法更改 java 文件,因为它会被覆盖。
Fastfile 中的一行可能有用:
desc 'Compile a new build for Android'
lane :build do |options|
Dir.chdir('..') do
before_build(options)
ionic_build
sh("ionic cordova build android --device --release --aot false --environment prod --output-hashing all \
--sourcemaps false --extract-css true --named-chunks false --build-optimizer true --minifyjs=true \
--minifycss=true --optimizejs=true")
deeplinks(action: 'uninstall')
end
end
cordova-plugin-androidx-adapter 将迁移旧库以自动使用 AndroidX 支持库。我相信当您的目标是 Android 10 或更高时(即进行切换时),这是必需的。一旦您的所有插件都支持 AndroidX,您就可以删除适配器插件。
我有一个正在使用的 Ionic 项目,在构建 Android 时遇到问题。我继承了这个项目,所以这就是为什么我不是 100% 熟悉 Fastlane 以及它如何构建 java 文件。此外,我在 WSL2 上使用 sdkmanager 和以下已安装的软件包:
Installed packages:=====================] 100% Fetch remote repository...
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;29.0.2 | 29.0.2 | Android SDK Build-Tools 29.0.2 | build-tools/29.0.2
emulator | 30.8.4 | Android Emulator | emulator
patcher;v4 | 1 | SDK Patch Applier v4 | patcher/v4
platform-tools | 31.0.3 | Android SDK Platform-Tools | platform-tools
platforms;android-29 | 5 | Android SDK Platform 29 | platforms/android-29
当我 运行 bundle exec fastlane android build
它做了很多魔术,但最终导致以下错误:
> Task :app:compileReleaseJavaWithJavac FAILED
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:42: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
^
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/FileProvider.java:21: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {}
^
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:297: error: cannot find symbol
this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
^
symbol: method getUriForFile(Activity,String,File)
location: class FileProvider
/home/zonyx/git/gitlab/studio/platforms/android/app/src/main/java/org/apache/cordova/camera/CameraLauncher.java:824: error: cannot find symbol
Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
^
symbol: method getUriForFile(Activity,String,File)
location: class FileProvider
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
我看到一些关于使用 androidx.core.content.FileProvider
而不是 android.support.v4.content.FileProvider
的较新 SDK 版本的想法。由于整个 Android 部分是自动构建/生成的,我显然无法更改 java 文件,因为它会被覆盖。
Fastfile 中的一行可能有用:
desc 'Compile a new build for Android'
lane :build do |options|
Dir.chdir('..') do
before_build(options)
ionic_build
sh("ionic cordova build android --device --release --aot false --environment prod --output-hashing all \
--sourcemaps false --extract-css true --named-chunks false --build-optimizer true --minifyjs=true \
--minifycss=true --optimizejs=true")
deeplinks(action: 'uninstall')
end
end
cordova-plugin-androidx-adapter 将迁移旧库以自动使用 AndroidX 支持库。我相信当您的目标是 Android 10 或更高时(即进行切换时),这是必需的。一旦您的所有插件都支持 AndroidX,您就可以删除适配器插件。