andfun-kotlin-dessert-pusher
andfun-kotlin-dessert-pusher copied to clipboard
Issues building the app with Android Studio Hedgehog
Hey folks, I just started with this lesson and I had a lot of issues getting the app build. I initially checked out the starter-code
and went down a rabbit hole trying it to get the build and eventually gave up.
A coworker helped me and got the master
branch to run, but I had to tweak both the compileSdkVersion
and targetSdkVersion
to version 34, up from 31
Android Studio info:
Android Studio Hedgehog | 2023.1.1 Patch 1
Build #AI-231.9392.1.2311.11255304, built on December 26, 2023
Runtime version: 17.0.7+0-17.0.7b1000.6-10550314 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.1.2
GC: G1 Young Generation, G1 Old Generation
Memory: 3072M
Cores: 10
Metal Rendering is ON
Registry:
external.system.auto.import.disabled=true
ide.text.editor.with.preview.show.floating.toolbar=false
Non-Bundled Plugins:
com.github.copilot (1.4.4.3955)
google-java-format (1.17.0.0)
idea.plugin.protoeditor (231.9225.5)
I was using JDK 17, the one bundled with Android Studio.
However the starter-code
branch fails, from the get go, with this error:
Unsupported Java.
Your build is currently configured to use Java 17.0.7 and Gradle 6.1.1.
Possible solution:
- Upgrade Gradle wrapper to 7.2 version and re-import the project
Diffing between master
and this branch helps, but without some Git-foo and my colleague's help it would have been a nightmare to get this to run.
Here are some fixes I applied to the gradle files:
Build gradle (project):
buildscript {
ext {
//update kotlin version, I use 1.8.0
kotlin_version = "1.8.0"
}
repositories {
google()
mavenCentral()
}
dependencies {
>
//Update gradle classpath
classpath 'com.android.tools.build:gradle:8.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
Build gradle (:app):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
// apply plugin: 'kotlin-android-extensions'
android {
// Not sure if these compile options are actually necessary
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
// UPdate the targetSdkVersion and compileSdkVersion
compileSdkVersion 34
defaultConfig {
applicationId "com.example.android.dessertpusher"
minSdkVersion 19
targetSdkVersion 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
dataBinding true
}
productFlavors {
}
//Set the namespace
namespace 'com.example.android.dessertpusher'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.jakewharton.timber:timber:4.7.1'
}
Make sure the gradle version you have installed (in my case 8.0) matches your file
gradle wrapper properties:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/_gradle-8.0-bin.zip_
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Make sure to set android:exported="true" as this is required with the updated versions.
Android Manifest.xml:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_dessert_pusher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_dessert_pusher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hey, had the same issue few months ago and submitted a PR to fix it, but it hasn't been merged. Here's the pull request fixing this. Can repo owners look into merging it? https://github.com/udacity/andfun-kotlin-dessert-pusher/pull/26