如何查找已引入Android类的API级别?
我创建了一个新的Android项目,目标是API 15,并使用 androidx
。自动生成的 Hello world
是:
I created a new Android project, targeting API 15 and using androidx
. The autogenerated Hello world
is:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
添加 import androidx.webkit .WebViewAssetLoader
失败,并显示无法解析符号webkit
。
所以我尝试创建另一个项目,这次针对的是API级别27,结果相同,因此我得出结论,我需要的API是28(并且放弃了,因为我不想针对这样的限制)。有人在上发表评论建议不是这种情况,因此这个问题是双重的。
So I tried to create another project, this time targeting API level 27, with the same result, and I concluded that the API I needed was 28 (and gave up because I do not want to target something so restricting). Someone commenting on another question suggested that is not the case, hence this question, which is twofold.
-
在哪里可以找到哪个API达到特定班级目标的水平? 关于WebViewAssetLoader的文档没有说。
我在项目中缺少什么吗,例如其他可选的JAR?
Am I missing something in my project, e.g. additional JARs which are optional?
我得出的结论是,API我需要的是28
and I concluded that the API I needed was 28
这实际上不是这里发生的事情。
That's not really what's going on here.
您正在尝试导入 androidx.webkit.WebViewAssetLoader
。该软件包的第一部分是 androidx
。每个 androidx
类都来自一个库。显然,您根本没有该图书馆。
You are trying to import androidx.webkit.WebViewAssetLoader
. The first segment of that package is androidx
. Every androidx
class comes from a library. You simply don't have that library, apparently.
在理想的世界中,您可以访问该类的官方JavaDoc ,并告知哪个Jetpack库包含了该类。这不是一个理想的世界。
In an ideal world, you would be able to visit the official JavaDocs for that class and be told which Jetpack library contains it. This is not an ideal world.
因此,这就是为什么要麻烦维护 AndroidX Tech ,以填补其中一些文档空白。如果在类下拉列表中选择 W *,则会找到 WebViewAssetLoader
是 androidx.webkit:webkit
库版本 1.1.0 或更高版本。
So, that's why I go through the trouble of maintaining AndroidX Tech, to fill in some of these documentation gaps. If you choose "W*" in the "Classes" drop-down, you will find WebViewAssetLoader
is part of the androidx.webkit:webkit
library, version 1.1.0
or higher.
现在(2020-03-17), 1.2.0
是最新版本,因此添加:
Right now (2020-03-17), 1.2.0
is the most recent version, so add:
implementation "androidx.webkit:webkit:1.2.0"
到模块的版本中的
,您应该会很好。依赖项
.gradle
to your dependencies
in your module's build.gradle
, and you should be good to go.