[英]Cause: androidx.navigation.safeargs can only be used with an androidx project
I am facing issue with navigation component called safeargs
.我正面临名为
safeargs
的导航组件的问题。
I have used classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
in build.gradle.我在 build.gradle 中使用了
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
。
While applying plugin androidx.navigation.safeargs.kotlin
in app/build.gradle
, I am getting following error:在
app/build.gradle
中应用插件androidx.navigation.safeargs.kotlin
时,出现以下错误:
Cause: androidx.navigation.safeargs can only be used with an androidx project
原因:androidx.navigation.safeargs 只能与 androidx 项目一起使用
app/build.gradle应用程序/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs.kotlin'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.navigationexample"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
}
I am facing issue with navigation component called safeargs
.我遇到了名为
safeargs
导航组件的问题。
I have used classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
in build gradle.我在构建gradle中使用了
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
。
While applying plugin androidx.navigation.safeargs.kotlin
in app/build.gradle
, I am getting following error:在
app/build.gradle
androidx.navigation.safeargs.kotlin
中app/build.gradle
插件androidx.navigation.safeargs.kotlin
时,出现以下错误:
Cause: androidx.navigation.safeargs can only be used with an androidx project
原因:androidx.navigation.safeargs只能与androidx项目一起使用
app/build.gradle app / build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs.kotlin'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.navigationexample"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
}
I am facing issue with navigation component called safeargs
.我遇到了名为
safeargs
导航组件的问题。
I have used classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
in build gradle.我在构建gradle中使用了
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
。
While applying plugin androidx.navigation.safeargs.kotlin
in app/build.gradle
, I am getting following error:在
app/build.gradle
androidx.navigation.safeargs.kotlin
中app/build.gradle
插件androidx.navigation.safeargs.kotlin
时,出现以下错误:
Cause: androidx.navigation.safeargs can only be used with an androidx project
原因:androidx.navigation.safeargs只能与androidx项目一起使用
app/build.gradle app / build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs.kotlin'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.navigationexample"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
}
The only thing that worked for me was.唯一对我有用的是。
In top of build.gradle file for the project:在项目的 build.gradle 文件之上:
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.4.2"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
In the same file under plugins add:在插件下的同一文件中添加:
plugins {
...
id 'androidx.navigation.safeargs.kotlin' version '2.4.2' apply false
}
In the build.gradle file for Module, under plugins add:在 Module 的 build.gradle 文件中,在 plugins 下添加:
plugins {
...
id 'androidx.navigation.safeargs.kotlin'
}
I am facing issue with navigation component called safeargs
.我遇到了名为
safeargs
导航组件的问题。
I have used classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
in build gradle.我在构建gradle中使用了
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
。
While applying plugin androidx.navigation.safeargs.kotlin
in app/build.gradle
, I am getting following error:在
app/build.gradle
androidx.navigation.safeargs.kotlin
中app/build.gradle
插件androidx.navigation.safeargs.kotlin
时,出现以下错误:
Cause: androidx.navigation.safeargs can only be used with an androidx project
原因:androidx.navigation.safeargs只能与androidx项目一起使用
app/build.gradle app / build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs.kotlin'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.navigationexample"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
}
If you have added the below lines in Gradle properties file then its okay如果您在 Gradle 属性文件中添加了以下几行,则可以
android.useAndroidX=true
android.enableJetifier=true
Please add this line to your project-level build.gradle请将此行添加到您的项目级 build.gradle
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
or current updated version.或当前更新版本。
I am facing issue with navigation component called safeargs
.我遇到了名为
safeargs
导航组件的问题。
I have used classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
in build gradle.我在构建gradle中使用了
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.0.0'
。
While applying plugin androidx.navigation.safeargs.kotlin
in app/build.gradle
, I am getting following error:在
app/build.gradle
androidx.navigation.safeargs.kotlin
中app/build.gradle
插件androidx.navigation.safeargs.kotlin
时,出现以下错误:
Cause: androidx.navigation.safeargs can only be used with an androidx project
原因:androidx.navigation.safeargs只能与androidx项目一起使用
app/build.gradle app / build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs.kotlin'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.navigationexample"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
}
Solution解决方案
Create gradle.properties
file inside app (if not exist already) folder and add the content of this example file into it.在 app(如果不存在)文件夹中创建
gradle.properties
文件,并将此示例文件的内容添加到其中。 Sync your project and it worked for me.同步您的项目,它对我有用。
Example gradle.properties File 示例 gradle.properties 文件
Chill Pill :)清凉丸:)
If you have multiple modules, you have to put the classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
into build.graddle
in the root of project, not the one in the module.如果您有多个模块,则必须将
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
放入项目根目录中的build.graddle
中,而不是模块中的目录中。 Then you can use id "androidx.navigation.safeargs"
in the module.然后你可以在模块中使用
id "androidx.navigation.safeargs"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.