android - Flutter Build Fails: InAppWebView error: package okhttp3 does not exist
问题描述
说明 添加 youtube_player_flutter v8.0.0(链接:https ://github.com/sarbagyastha/youtube_player_flutter )时,Flutter (android) 应用程序无法构建并显示以下错误日志:
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\in_app_webview\InAppWebView.java:97: error: package okhttp3 does not exist
import okhttp3.OkHttpClient;
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\in_app_webview\InAppWebView.java:121: error: cannot find symbol
public OkHttpClient httpClient;
^
symbol: class OkHttpClient
location: class InAppWebView
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:24: error: package okhttp3 does not exist
import okhttp3.Request;
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:25: error: package okhttp3 does not exist
import okhttp3.Response;
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\Util.java:46: error: package okhttp3 does not exist
import okhttp3.OkHttpClient;
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\Util.java:175: error: cannot find symbol
public static OkHttpClient getUnsafeOkHttpClient() {
^
symbol: class OkHttpClient
location: class Util
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\in_app_webview\InAppWebView.java:184: error: cannot find symbol
httpClient = new OkHttpClient().newBuilder().build();
^
symbol: class OkHttpClient
location: class InAppWebView
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:180: error: cannot find symbol
Request mRequest = new Request.Builder().url(urlHttps).build();
^
symbol: class Request
location: class ContentBlockerHandler
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:180: error: package Request does not exist
Request mRequest = new Request.Builder().url(urlHttps).build();
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:181: error: cannot find symbol
Response response = null;
^
symbol: class Response
location: class ContentBlockerHandler
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:231: error: cannot find symbol
Request mRequest = new Request.Builder().url(url).head().build();
^
symbol: class Request
location: class ContentBlockerHandler
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:231: error: package Request does not exist
Request mRequest = new Request.Builder().url(url).head().build();
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\content_blocker\ContentBlockerHandler.java:232: error: cannot find symbol
Response response = null;
^
symbol: class Response
location: class ContentBlockerHandler
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\Util.java:201: error: package OkHttpClient does not exist
OkHttpClient.Builder builder = new OkHttpClient.Builder();
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\Util.java:201: error: package OkHttpClient does not exist
OkHttpClient.Builder builder = new OkHttpClient.Builder();
^
C:\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_inappwebview-5.3.2\android\src\main\java\com\pichillilorenzo\flutter_inappwebview\Util.java:210: error: cannot find symbol
OkHttpClient okHttpClient = builder
^
symbol: class OkHttpClient
location: class Util
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.
16 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':flutter_inappwebview: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 27s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
配置 我有以下配置:
颤振医生输出:
[√] Flutter (Channel master, 2.3.0-17.0.pre.411, on Microsoft Windows [Version 10.0.19042.1052], locale en-IN)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.0)
[√] VS Code (version 1.57.1)
[√] Connected device (3 available)
发布规范.yaml:
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.1
get_it:
google_fonts: ^2.1.0
shimmer: ^2.0.0
lottie: ^1.0.1
stacked: ^2.1.9
firebase_core: ^1.4.0
cloud_firestore: ^2.4.0
firebase_auth: ^3.0.1
firebase_analytics: ^8.2.0
pin_code_fields: ^7.2.0
geolocator: ^7.1.0
google_maps_flutter: ^2.0.6
geocoding: ^2.0.0
url_launcher: ^6.0.6
rflutter_alert: ^2.0.2
sms_autofill: ^2.0.0
carousel_slider: ^4.0.0
razorpay_flutter: ^1.2.6
flutter_tts: ^3.1.0
intl: ^0.17.0
webview_flutter: ^2.0.8
flutter_icons:
git:
url: https://github.com/adarsh-technocrat/flutter-icons
timelines: ^0.1.0
scrollable_positioned_list: ^0.1.10
in_app_review: ^2.0.2
share: ^2.0.4
connectivity: ^3.0.6
cached_network_image: ^3.0.0
youtube_player_flutter: ^8.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: "^0.9.0"
构建.gradle 文件:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
技术细节:
- 设备:华硕Z01RD(手机)
- 操作系统:安卓
- 版本安卓 10
已经尝试过的解决方案
我已经在互联网上搜索了很多解决方案,也尝试了一些我自己的技巧,但都是徒劳的。
这是相同的列表:
- 尝试了这里提到的解决方案:https ://github.com/sarbagyastha/youtube_player_flutter/issues/490
- 我尝试升级 gradle 版本。
- 我尝试运行全新安装。
- 我尝试将完整的应用程序升级为空安全,因此使用
environment: sdk: ">=2.12.0 <3.0.0"
- 尝试通过 pubspec.yaml 显式安装 flutter_inappwebview 插件。
- 尝试删除我认为可能存在冲突的其他一些现有依赖项(例如 webview_flutter 插件)。
- 尝试将所有依赖项列表升级到最新版本。
解决方案
安装Java 8,因为它是推荐且稳定的。确保 JRE 和 JDK 都应该是版本 8。卸载您已安装的任何其他版本。
推荐阅读
- ios - Swift 4.2:无法使用面向协议的委托概念向自定义 UITableViewCell 添加自定义行为
- java - 如何在不使用 youtube api 的情况下通过 JAVA 中的 HTTP POST 上传视频文件
- listview - 如何避免在滚动具有大量项目的列表视图时出现灰色
- image - 垂直滚动视图在 xamarin 表单中不起作用。?
- laravel - Bootstrap 4 打破了条纹元素
- php - 使用 curl php codeigniter 将图像从一台服务器上传到另一台服务器
- java - 在 java fx 中滚动列表视图时避免 updateItem
- javascript - 将此 PCRE 转换为 Javascript 正则表达式
- javascript - 保护元素免受全局 CSS
- c# - 将异步方法传递给 Parallel.ForEach