Comments (7)
Made following changes:
diff --git a/app/build.gradle b/app/build.gradle
index d19be74..3bea24b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -23,14 +23,21 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'
android {
- compileSdkVersion 30
+ compileSdkVersion 34
buildFeatures {
dataBinding true
}
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+ kotlinOptions {
+ jvmTarget = '17'
+ }
defaultConfig {
applicationId 'com.example.android.navigation'
- minSdkVersion 19
- targetSdkVersion 30
+ minSdkVersion 21
+ targetSdkVersion 33
vectorDrawables.useSupportLibrary = true
versionCode 1
versionName "1.0"
@@ -43,16 +50,14 @@ android {
}
productFlavors {
}
+ namespace 'com.example.android.navigation'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
- // Kotlin
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version_kotlin"
-
// Constraint Layout
- implementation "androidx.constraintlayout:constraintlayout:$version_constraint_layout"
+ implementation "androidx.constraintlayout:constraintlayout:2.1.4"
// Core
implementation "androidx.core:core:$version_core"
@@ -60,7 +65,22 @@ dependencies {
// Material Design
implementation "com.google.android.material:material:$version_material"
- // Navigation
- implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation"
- implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation"
+ def nav_version = "2.7.0"
+
+ // Java language implementation
+ implementation "androidx.navigation:navigation-fragment:$nav_version"
+ implementation "androidx.navigation:navigation-ui:$nav_version"
+
+ // Kotlin
+ implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
+ implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
+
+ // Feature module Support
+ implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
+
+ // Testing Navigation
+ androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
+
+ // Jetpack Compose Integration
+ implementation "androidx.navigation:navigation-compose:$nav_version"
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index eb917a8..cba0193 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -15,8 +15,7 @@
~ limitations under the License.
-->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.android.navigation">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
@@ -27,7 +26,8 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
- android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout">
+ android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout"
+ android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
diff --git a/app/src/main/java/com/example/android/navigation/MainActivity.kt b/app/src/main/java/com/example/android/navigation/MainActivity.kt
index c21b120..ff07b9e 100644
--- a/app/src/main/java/com/example/android/navigation/MainActivity.kt
+++ b/app/src/main/java/com/example/android/navigation/MainActivity.kt
@@ -39,7 +39,7 @@ class MainActivity : AppCompatActivity() {
appBarConfiguration = AppBarConfiguration(navController.graph, drawerLayout)
// prevent nav gesture if not on start destination
navController.addOnDestinationChangedListener { nc: NavController, nd: NavDestination, bundle: Bundle? ->
- if (nd.id == nc.graph.startDestination) {
+ if (nd.id == nc.graph.startDestinationId) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
} else {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
diff --git a/app/src/main/java/com/example/android/navigation/TitleFragment.kt b/app/src/main/java/com/example/android/navigation/TitleFragment.kt
index 16a7883..7ff90d5 100644
--- a/app/src/main/java/com/example/android/navigation/TitleFragment.kt
+++ b/app/src/main/java/com/example/android/navigation/TitleFragment.kt
@@ -33,10 +33,13 @@ import com.example.android.navigation.databinding.FragmentTitleBinding
class TitleFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
+
val binding: FragmentTitleBinding = DataBindingUtil.inflate(
inflater, R.layout.fragment_title, container, false)
- binding.playButton.setOnClickListener { v: View ->
- v.findNavController().navigate(TitleFragmentDirections.actionTitleFragmentToGameFragment())
+
+ binding.playButton.setOnClickListener { view: View ->
+ Navigation.findNavController(view).navigate(R.id.action_titleFragment_to_gameFragment)
+// view.findNavController().navigate(TitleFragmentDirections.actionTitleFragmentToGameFragment())
}
setHasOptionsMenu(true)
return binding.root
commit d67dd3273bde60d3ac8224afbeb8f7d7c7498ac5
diff --git a/build.gradle b/build.gradle
index 42c636d..45640d8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -17,19 +17,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
- version_kotlin = "1.3.72"
- version_core = "1.3.1"
- version_constraint_layout = "2.0.0-rc1"
+ version_kotlin = '1.8.0'
+ version_core = '1.10.1'
version_lifecycle_extensions = "2.2.0"
- version_material = "1.2.0"
- version_navigation = "2.3.0"
+ version_material = '1.9.0'
+ version_navigation = '2.7.0'
}
repositories {
google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:4.0.1'
+ classpath 'com.android.tools.build:gradle:8.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
commit d67dd3273bde60d3ac8224afbeb8f7d7c7498ac5
diff --git a/gradle.properties b/gradle.properties
index 15120a8..e618b54 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -22,7 +22,10 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
+android.defaults.buildfeatures.buildconfig=true
android.enableJetifier=true
+android.nonFinalResIds=false
+android.nonTransitiveRClass=false
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
With above changes, it built and deployed on emulator just fine. Hope above helps!
from andfun-kotlin-android-trivia.
Made following changes:
With above changes, it built and deployed on emulator just fine. Hope above helps!
Just vouching that as of 9/19/23 the above patches worked on a fresh install of Android Studio, at least on my macOS machine. This should help anyone trying to complete the App Navigation lesson in the Udacity course that links to this repo! Thanks @0x10FF !!!
from andfun-kotlin-android-trivia.
As of 9/20/2023, I also agree with retrospectmike. Works great as the starter code as it now builds and runs now on all my physical and virtual devices.
from andfun-kotlin-android-trivia.
For those who are trying the "Adding a Menu" exercise that follows and finding trouble with the now-deprecated onCreateOptionsMenu
functions, you can add the following code to the bottom of onCreateView
, above return binding.root
:
(requireActivity() as MenuHost).addMenuProvider(object: MenuProvider {
override fun onPrepareMenu(menu:Menu){
//handle eg visibility of menu items.. nothing here now
}
override fun onCreateMenu(menu: Menu, menuInflater:MenuInflater){
menuInflater.inflate(R.menu.overflow_menu, menu)
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
//validate and handle selected menu item
return NavigationUI.onNavDestinationSelected(menuItem!!,
requireView().findNavController())
}
},viewLifecycleOwner, Lifecycle.State.RESUMED)
It would be instead of the tutorial's onCreateOptinsMenu(..) and onOptionsItemSelected(..)
You'll need to add the proper imports as indicated by the IDE.
Credit to a medium page I found called How To Migrate The Deprecated onCreateOptionsMenu for the approach.
from andfun-kotlin-android-trivia.
Related Issues (20)
- GameWonFragment compiler error when implementing SafeArgs HOT 20
- Fails to build in Android Studio 3.4, citing Gradle errors or IDE fatal error HOT 2
- E/ViewRootImpl: sendUserActionEvent() mView == null HOT 3
- AndroidX implementation HOT 4
- Navigation drawer not closing HOT 5
- Can't use safe args HOT 2
- Can't add "layout_gravity" property to NavigationView in DrawerLayout HOT 5
- Can't build the project as license for sdk is not accepted
- Gradle sync failure. Could not find androidx.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07. HOT 2
- GameWonFragment compiler error when passing fragment in ShareCompat.IntentBuilder.from() HOT 6
- Step.09-Solution not working HOT 2
- Redundant code in GameFragment.kt (Branch: Step.03-Exercise-Conditional-Navigation)
- Gradle sync failure. Failure to resolve - android.arch.navigation:navigation-fragment-ktx:2.3.0, - android.arch.navigation:navigation-ui-ktx:2.3.0 HOT 3
- Unsolved referense
- deprecated way for options Menu HOT 1
- Adding the Up-Button causes app crashing
- Incompatible Kotlin/Gradle Version on Branch Step.01-Exercise-Creating-and-Adding-a-Fragment HOT 4
- Method onSupportNavigateUp: Sequence of method arguments interchanged HOT 4
- ActivityMainBinding and FragmentTitleBinding unresolved reference HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from andfun-kotlin-android-trivia.