Open ahmedMubarak2024 opened 1 year ago
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 !!!
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.
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.
+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.
@0x10FF after made these changes build failed with : Unsupported Java. Your build is currently configured to use Java 17.0.9 and Gradle 6.1.1.
+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.
@0x10FF after made these changes build failed with : Unsupported Java. Your build is currently configured to use Java 17.0.9 and Gradle 6.1.1.
I changed my jdk to 13 and I worked successfully.
Just confirming that the changes proposed by @0x10FF worked for me on Android Studio Koala on macOS as on 17/06/24
I was also able to upgrade the gradle and dependencies. Made the following changes.
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
project/build.gradle
version_kotlin = '2.0.0'
version_core = '1.13.1'
version_lifecycle_extensions = "2.2.0"
version_material = '1.12.0'
version_navigation = '2.7.7'
classpath 'com.android.tools.build:gradle:8.5.0'
Made following changes:
With above changes, it built and deployed on emulator just fine. Hope above helps!