22

我想使用导航架构组件。

但是我在导入安全参数时遇到了问题

同步消息:

找不到 androidx.navigation:safe-args-gradle-plugin:1.0.0-alpha01。在以下位置搜索:
https://dl.google.com/dl/android/maven2/androidx/navigation/safe-args-gradle-plugin/1.0.0-alpha01/safe-args-gradle-plugin-1.0。 0-alpha01.pom
https://dl.google.com/dl/android/maven2/androidx/navigation/safe-args-gradle-plugin/1.0.0-alpha01/safe-args-gradle-plugin-1.0.0 -alpha01.jar
https://jcenter.bintray.com/androidx/navigation/safe-args-gradle-plugin/1.0.0-alpha01/safe-args-gradle-plugin-1.0.0-alpha01.pom
https:// /jcenter.bintray.com/androidx/navigation/safe-args-gradle-plugin/1.0.0-alpha01/safe-args-gradle-plugin-1.0.0-alpha01.jar
要求:
项目:

我关注了将组件添加到您的项目,但没有解决我的问题。

项目:build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath "androidx.navigation:safe-args-gradle-plugin:1.0.0-alpha01"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块:build.gradle

apply plugin: 'com.android.application'
apply plugin: 'androidx.navigation.safeargs'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.mangoslab.navigation"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    def nav_version = "1.0.0-alpha01"

    implementation "android.arch.navigation:navigation-fragment:${nav_version}" // use -ktx for Kotlin
    implementation "android.arch.navigation:navigation-ui:${nav_version}" // use -ktx for Kotlin

    // optional - Test helpers
    androidTestImplementation "android.arch.navigation:navigation-testing:${nav_version}" // use -ktx for Kotlin
}
4

9 回答 9

35

尝试添加

classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha01" 

代替

classpath "androidx.navigation:safe-args-gradle-plugin:1.0.0-alpha01"
于 2018-05-11T08:19:09.253 回答
9

现在您可以使用以下类路径来将安全参数与 AndroidX 一起使用

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha02"

有关更多详细信息,您可以在此处查看

于 2019-04-10T10:09:59.333 回答
3

从 Google maven 存储库
http://joxi.ru/GrqxKRgiQn1OZA检查包

于 2018-05-11T15:01:58.623 回答
3

接受的答案对我不起作用。但是当我使用它时,alpha 5它起作用了

项目build.gradle

classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha05"
于 2018-08-23T21:06:07.927 回答
3

我只是按照androidx导航发布文档 Jetpack库导航框架

在我添加的依赖项块内的应用程序级别 build.gradle 文件中

def nav_version = "2.1.0"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.navigation:navigation-runtime:$nav_version"

您还需要在文件顶部添加以下内容

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

在项目顶级 build.gradle 文件中包含以下类路径

    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0"
于 2019-11-09T18:31:48.643 回答
2

以上所有对我都不起作用。我只需要放在 apply plugin: "androidx.navigation.safeargs.kotlin"后面 apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions'

于 2019-05-03T05:12:55.467 回答
2

我通过更换解决了这个问题

classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$version_navigation" 

在项目级别构建中 version_navigation = "2.1.0" with

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
于 2019-09-07T06:29:31.453 回答
0

就我而言,我必须添加这个插件:

apply plugin: "androidx.navigation.safeargs.kotlin"

在底部并且完美地工作。

于 2019-07-30T09:10:38.490 回答
0

请按照以下步骤解决您的问题

1. build.gradle模块级

将此添加到文件顶部

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'androidx.navigation.safeargs'
}

添加以下依赖项

implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

2. build.gradle项目级

dependencies {
    classpath "com.android.tools.build:gradle:7.0.2"
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31'
    classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5'
}
于 2021-11-15T08:04:48.003 回答