Since a recent upgrade of Android Studio, I cannot build my project anymore. The surface error is:
e: C:\Users\<user>\dev\<project>\app\build\generated\source\navigation-args\release\com\<org>\<project>\ui\home\HomeFragmentDirections.kt: (3, 8): Unresolved reference: R
If I dig further and build from the terminal with gradlew (gradlew assembleDebug --debug):
FAILURE: Build failed with an exception.
What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at '/mnt/c/Users/<user>/dev/<project>/local.properties'.
My local.properties file already contains this line:
sdk.dir=C\:\\Users\\<user>\\AppData\\Local\\Android\\Sdk
and that is where the SDK is installed.
In my build.gradle:
...
android {
compileSdkVersion 32
buildToolsVersion '32.1.0-rc1'
...
defaultConfig {
...
minSdkVersion 23
targetSdkVersion 32
...
}
settings.gradle:
include ':app'
rootProject.name = "<projectname>"
What I tried:
As per the error, I set the ANDROID_HOME environment variable to the
SDK location C:\Users\<user>\AppData\Local\Android\Sdk, and
restarting my machine to make sure the var is seen.
Clean project, rebuild project
File -> Invalidate caches
Install different versions of the SDK and SDK Tools
Reinstalling the SDK completely
Reinstalling Android Studio completely
I found innumerable posts with a problem similar to mine, and all seem to be solved by upgrading the SDK, changing compileSdkVersion/buildToolsVersion etc. in build.gradle, changing the SDK location in local.properties or the ANDROID_HOME environment variable. Or even reverting to an older SDK version. None of that works for me.
I'm out of options at this point. Any help/idea would be appreciated.
Current software:
Android Studio:
Android Studio Chipmunk | 2021.2.1
Build #AI-212.5712.43.2112.8512546, built on April 28, 2022
Runtime version: 11.0.12+7-b1504.28-7817840 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin (212-1.6.21-release-334-AS5457.46)
Android SDK: Android API 32 (Sv2)
Build-Tools installed: 32.1.0-rc1, 32.0.0, 30.0.3
ext.kotlin_version = "1.6.21"
Operating system: Windows 10
Related
I've added my SDK to Android Studio, but it doesn't appear in External Libraries, and gradle fails to sync.
Steps I followed:
Created my SDK in my AOSP build tree
In AS:
SDK Manager: I added my SDK as an SDK Update Site
SDK Platforms: Installed my SDK
Project Structure: Modules: Compile Sdk Version: I selected my SDK. This modifies my compileSdkVersion in my build.gradle file.
At this point, gradle attempts to sync and failed. The log shows:
com.android.tools.idea.gradle.project.sync.idea.issues.SdkPlatformNotFoundException: Module: 'mobile' platform 'MATT:MATT SDK Add-On LOCAL_BUILD:30' not found.
(mobile is the name of my module)
Thing is, everything appears correct. I see the SDK installed exactly where I would expect it in my SDK directory. As I mentioned above, the Project Structure dialog picks it up and writes it to the gradle file. I'm invalidated my cache, restarted, re-tried everything, everything I can think of. The name of the compileSdkVersion appears to be exactly what the XML dictates it should be (and it was all loaded by AS, I didn't manually type it)
I also do not see my SDK in the External Libraries tree in the Project's View
My AS version is
Android Studio Arctic Fox | 2020.3.1 Canary 14
Build #AI-203.7717.56.2031.7260174, built on April 5, 2021
Runtime version: 11.0.9.1+0-b77-7246554 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.8.0-44-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 28
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin
Current Desktop: i3
Though I had a co-worker who was previously able to set this up also run into this issue. I suspect there's some subtle step we're missing.
Other settings:
android {
compileSdkVersion 'MATT:MATT SDK Add-On LOCAL_BUILD:30'
buildToolsVersion '30.0.1'
// ...
}
I've played with other installed buildToolsVersion versions to no avail.
In project settings (File -> Project Structure) 'Android NDK location' field is greyed out:
Clicking on 'Download Android NDK' briefly displays some dialog. There are several versions of NDK installed:
What is wrong with my setup?
Host: Ubuntu 18.04 LTS
Android Studio 4.1.1
Build #AI-201.8743.12.41.6953283, built on November 5, 2020
Runtime version: 1.8.0_242-release-1644-b3-6222593 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-128-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 2014M
Cores: 4
Registry: ide.new.welcome.screen.force=true, external.system.auto.import.disabled=true, debugger.watches.in.variables=false
Non-Bundled Plugins: com.intellij.ideolog, org.jetbrains.kotlin
Current Desktop: LXDE
Submitted bug report
Leave SDK Location ;) we can still select from Files> Project
Structure> Modules> NDK Version
Or, Simply Add
ndkVersion '22.0.7026061'
in build.gradle(app) like this
externalNativeBuild {
ndkBuild {
path file('src/main/jni/Android.mk')
}
}
ndkVersion '22.0.7026061' // your desire version
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
Extra Tips:--- you can set path variable here
Still App not Building for NDK ??
Close Android Studio.
Delete .temp folder located
C:\Users\%USERNAME%\AppData\Local\Android\Sdk (if exist)
Delete Options Folder located in
C:\Users\%USERNAME%\AppData\Roaming\Google\AndroidStudio4.1\
Delete NDK or ndk-bundle folder located in your SDK directory... in my case D:\Android\SDK\ndk
Now clean temps from SDK Manager > Optimize disk Space [don't worry it will not delete your essential files]
Now, install your desire NDK version from SDK Manager
I had this problem and by setting NDK value in local.properties file of my project, that problem gone
ndk.dir=D\:\\mySdkFolder\\sdk\\myNdkFolder
sdk.dir=D\:\\mySdkFolder\\sdk
With a project open, click Tools > SDK Manager.
Click the SDK Tools tab.
Select the NDK (Side by side) and CMake checkboxes.
So I want to use var keyword in Android studio. So I download the latest JDK and changed my project to point to it:
Now when I sync I get this error:
12:37 PM Gradle sync failed: Cause: invalid type code: 19
Consult IDE log for more details (Help | Show Log) (684 ms)
my Android gradle plugin version is 4.0.1 and Gradle version is 6.1.1
EDIT: I think maybe Android Studio only supports up to JDK 8: https://developer.android.com/studio/write/java8-support
It might be the problem, that Gradle 6.0 (and 6.1) does not support JDK 14. Only JDK 13 and older are supported.
https://docs.gradle.org/6.0/release-notes.html#support-for-java-13
https://docs.gradle.org/6.0/release-notes.html#upgrade-instructions
I am trying to build an Android app using Gradle on Ubuntu 18.04. Android Studio is not installed o the machine (I use Eclipse for development but maintain a gradle toolchain).
The toolchain has worked on a different machine running Ubuntu 16.04. However, it does not work with gradle 3.4.1, which ships with 18.04, so I had to upgrade my build config. On the 18.04 machine, I changed the dependency
classpath 'com.android.tools.build:gradle:2.1.2'
to
classpath 'com.android.tools.build:gradle:2.3.0'
and changed
buildToolsVersion "23.0.3"
to
buildToolsVersion "25.0.3"
Now when I run gradle build, I get the following error message:
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
However, I have ANDROID_HOME set and pointing to ~/bin/android-sdk-linux, which is the root dir of my Android SDK setup. Also, I have Android SDK build tools 25.0.3 installed locally.
What gives?
Apparently Gradle does not honor ANDROID_HOME, despite the error message saying otherwise.
As a workaround,
echo sdk.dir=$ANDROID_HOME >> local.properties
in the project root dir has fixed this (after also ensuring I was using the correct JDK version and had all submodules checked out).
Oddly, however, on a different computer (also running Ubuntu 18.04) the same app builds without local.properties being present.
If there is no local.properties, just go ahead and create one in parallel to gradle directory.
Then add this line,
sdk.dir=/Users/YOUR_USERNAME/Library/Android/sdk
I had installed JDK 10.0.1 on my pc with windows 10 and I tried to build an app with ionic Cordova build android --prod -- release.
But I got the warning:
Requirements check failed for JDK 1.8 or greater.
I checked the environmental variables and they seem to be correct. What should I do?