为什么我的导航组件没有生成方向?

Why isn't my navigation component generating the Directions?

提问人:Kalaitos Ornitier 提问时间:10/19/2023 更新时间:10/19/2023 访问量:48

问:

我遇到了一个已经完成的项目的gradle问题,不得不从头开始重新制作项目,除了导航不能正常工作,它没有生成方向之外,一切都很好

我在其他帖子中搜索了答案,但没有一个对我有用,而且我自己对gradle解决它不太了解,我附上了所有可能涉及的文件:

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Unscramble"
        tools:targetApi="31" >

        <activity android:name=".MainActivity"
            android:exported="true"
            android:screenOrientation="sensorPortrait"
            android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>


</manifest>

build.gradle (项目):

plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
    id 'androidx.navigation.safeargs' version '2.7.4' apply false
}

build.gradle(应用):

buildscript {
    repositories {
        google()
    }
    dependencies {
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.7.4")
    }
}

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

android {
    namespace 'com.example.unscramble'
    compileSdk 34

    defaultConfig {
        applicationId "com.example.unscramble"
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.10.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.google.code.gson:gson:2.10.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    //LiveData
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'

    //ViewModel
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
    implementation 'androidx.fragment:fragment-ktx:1.6.1'

    // Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:2.7.4"
    implementation "androidx.navigation:navigation-ui-ktx:2.7.4"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

settings.gradle:

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "unscramble"
include ':app'
Android Kotlin 移动 android-gradle-plugin

评论

0赞 JustSightseeing 10/19/2023
好的,导入和设置似乎正确完成,唯一的解决方案可能是:1)您没有在 navGraph 本身中创建任何方向 2) 您需要清理和重建您的项目或只是使缓存无效
0赞 Kalaitos Ornitier 10/19/2023
我肯定已经创建了方向,因为我在另一个项目和这里都有它们,不仅如此,而且我试图将旧文件复制粘贴到这个项目上并从头开始重新制作它,但没有一个有效,我尝试清理和重建了十几次,但一无所获,我只是试图使缓存无效,但无济于事。

答: 暂无答案