Flutter Build Fails: InAppWebView error: package okhttp3 does not exist
Posted
技术标签:
【中文标题】Flutter Build Fails: InAppWebView error: package okhttp3 does not exist【英文标题】: 【发布时间】:2021-10-01 21:10:15 【问题描述】:说明 添加 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)
Pubspec.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"
Build.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
技术细节:
设备:ASUS Z01RD(手机) 操作系统:Android Android 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 插件)。
已尝试将所有依赖项列表升级到最新版本。
【问题讨论】:
【参考方案1】:安装Java 8,因为它是推荐且稳定的。确保 JRE 和 JDK 都应该是版本 8。卸载您已安装的任何其他版本。
【讨论】:
以上是关于Flutter Build Fails: InAppWebView error: package okhttp3 does not exist的主要内容,如果未能解决你的问题,请参考以下文章
Yarn Run Build Fails , TypeError: _module.default.createRequireFromPath is not a function
Flutter:读取 build.yaml 文件中传递给 build_runner 的变量
如何修复 Flutter build_runner 错误:无法预编译 build_runner:build_runner: