为什么在我没有采取必要的依赖关系时导入 Android?
Why Androidx is being imported when I didn't take the nessessary dependencies?
我在 android 应用中使用了 AppCompat 库。最近我决定迁移到 AndroidX 组件。所以在我的 gradle.properties
中,我采用了这个:
android.useAndroidX=true
android.enableJetifier=true
并在 build.gradle
文件中获取 appcompat 依赖项:
implementation 'androidx.appcompat:appcompat:1.0.0'
但奇怪的是,我可以使用生命周期、viewmodel 等 jetpack 库,而无需在那里导入任何更多依赖项。是否有任何我不知道的隐藏功能允许我使用这些库?甚至当我从 gradle 文件中删除“implementation 'androidx.appcompat:appcompat:1.0.0'
”时,它也可以正常工作而不会出现任何编译错误。现在我很困惑,谁能给我一个合理的理由?我已经重建,删除缓存,甚至我已经多次重新启动我的电脑,但它有效。这怎么可能?顺便说一句,我的根级别 build.gradle 文件有这个:
buildscript {
repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
基本上,架构组件 集成在Android SDK 本身,无论您是否使用它。那是因为它开箱即用地为 SDK 组件的 Activity/Fragment
的 Lifecycle 提供支持,这就是为什么您能够看到 Jetpack 库,例如 viewmodel & 生命周期.
因此,导入 androidx.appcompat:appcompat
工件将解决它对视图模型和生命周期的内部依赖性 (即由于 AppCompatActivity 和依赖它的其他组件) 这就是为什么你能看到它。
我在 android 应用中使用了 AppCompat 库。最近我决定迁移到 AndroidX 组件。所以在我的 gradle.properties
中,我采用了这个:
android.useAndroidX=true
android.enableJetifier=true
并在 build.gradle
文件中获取 appcompat 依赖项:
implementation 'androidx.appcompat:appcompat:1.0.0'
但奇怪的是,我可以使用生命周期、viewmodel 等 jetpack 库,而无需在那里导入任何更多依赖项。是否有任何我不知道的隐藏功能允许我使用这些库?甚至当我从 gradle 文件中删除“implementation 'androidx.appcompat:appcompat:1.0.0'
”时,它也可以正常工作而不会出现任何编译错误。现在我很困惑,谁能给我一个合理的理由?我已经重建,删除缓存,甚至我已经多次重新启动我的电脑,但它有效。这怎么可能?顺便说一句,我的根级别 build.gradle 文件有这个:
buildscript {
repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
基本上,架构组件 集成在Android SDK 本身,无论您是否使用它。那是因为它开箱即用地为 SDK 组件的 Activity/Fragment
的 Lifecycle 提供支持,这就是为什么您能够看到 Jetpack 库,例如 viewmodel & 生命周期.
因此,导入 androidx.appcompat:appcompat
工件将解决它对视图模型和生命周期的内部依赖性 (即由于 AppCompatActivity 和依赖它的其他组件) 这就是为什么你能看到它。