Layout Inspector not working on Android Studio - android

I am getting the following error when trying to use Android Studio Layout inspector to debug my composables
Could not download androidx.compose.ui:ui:writeVersionFile .... (See a picture)
How can I fix this?
Addition Info
Mac M1 Chip
Android Studio Flamingo | 2022.2.1 Beta 2
Internet: OK

Add the mavenCentral() repository in your project's build.gradle
file:
allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}
Reload your project and update Gradle dependencies.
dependencies {
implementation("androidx.compose.ui:ui:1.3.3")
}
android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.2"
}
kotlinOptions {
jvmTarget = "1.8"
}
}
You can find more information at this link
[https://developer.android.com/jetpack/androidx/releases/compose-ui]

I faced the same issue here. The kotlinCompilerExtensionVersion 1.4.2 isn't released. The latest version is 1.4.1-dev-k1.8.10-c312d77f4cb.

Related

Android Studio Duplicate class kotlin

Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.3.31 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31)
Duplicate class kotlin.jdk7.AutoCloseableKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.3.31 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31)
**./gradlew clean **
build.gradle file:
buildscript {
ext {
buildToolsVersion = "30.0.0"
minSdkVersion = 23
compileSdkVersion = 33
targetSdkVersion = 30
googlePlayServicesAuthVersion = "16.0.1"
kotlinVersion = "1.8.0"
}
firebase: [
bom : "26.0.0"
]
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
classpath "com.google.gms:google-services:4.3.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
repositories {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
mavenLocal()
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
url("$rootDir/../node_modules/jsc-android/dist")
}
maven { url 'https://maven.google.com' }
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
I had the same problem with my app. It failed to build because of duplicate classes found in modules jetified-kotlin-stdlib-1.8.0 and jetified-kotlin-stdlib-jdk8-1.6.10
With the link, shared by Igor VANIAN : https://kotlinlang.org/docs/whatsnew18.html#usage-of-the-latest-kotlin-stdlib-version-in-transitive-dependencies
I added
dependencies {
...
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
}
to my android/app/build.gradle and Android builds fine now
I started having the same issue in react native native on the android side. I upgraded Kotlin to version 1.8.0 and built the app again and the issue was fixed. Maybe trying upgrading the kotlin version.
In android/build.gradle update the following
kotlinVersion = "1.8.0"
and add this under dependencies
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
This can happen when you're using different versions for different Kotlin dependencies.
Try to check all Kotlin dependencies. In my case, issue was with this core-ktx
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Updating to this resolved issue
implementation "androidx.core:core-ktx:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Here kotlin_version = '1.7.0'. You can use your desired version.
Hope this will help others.
I was having the same problem since yesterday.
I found that the reason behind this could be the artifact merge in Kotlin 1.8.0. Here is an issue talking about this breaking change.
So setting kotlinVersion = "1.8.0" as #Narasimha said works. But I still didn't figure out what dependency changed overnight that somehow made kotlin-stdlib:1.8.0 appear in the build logs.
Thanks all, I solve it by doing two things
In android/build.gradle update the following
kotlinVersion = "1.8.0"
In android/app/build.gradle add the following in dependencies
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
I had the same issue today and I fixed it in a different way, if it helps anyone:
When I upgraded my kotlin to version 1.8 it started happening and I had to change my hilt version to 2.44. Now it's running normally.

How to update latest gradle version of kotlin library

I created a library in multiplatform in latest intellij. My intellj added the outdated gradle version
settings.gradle.kts
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:4.1.2"). // How to update to latest version and what is the use of 4.1.2?
}
}
}
}
rootProject.name = "xyz"
I commented above in my code. Can someone guide how can I update my gradle version to latest and what is the use of 4.1.2 that piece of code?
I tried to remove 4.1.2 below piece of code then I am getting issue
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:4.1.2")
}
}
}
Error
Build file '/Users/vmodi/IdeaProjects/abc/build.gradle.kts' line: 1
Plugin [id: 'com.android.application'] was not found in any of the following sources:
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
build.gradle.kts
plugins {
kotlin("multiplatform") version "1.6.21"
id("com.android.application")
}
group = "com.abc"
version = "0.0.1"
repositories {
google()
mavenCentral()
}
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
val ktorVersion = "2.0.0"
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-auth:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.3.2")
implementation("io.insert-koin:koin-core:3.2.0-beta-1")
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies {
implementation("io.ktor:ktor-client-darwin:$ktorVersion")
}
}
}
}
}
android {
compileSdk = 21
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
applicationId = "com.abc.kotlinmultiplatform"
minSdk = 21
targetSdk = 31
}
#Suppress("UnstableApiUsage")
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
IntelliJ version
IntelliJ IDEA 2022.1.1 (Ultimate Edition)
Build #IU-221.5591.52, built on May 10, 2022
Licensed to Vivek Modi
For educational use only.
Runtime version: 11.0.14.1+1-b2043.45 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 11.6.5
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Non-Bundled Plugins:
com.intellij.nativeDebug (221.5591.54)
org.jetbrains.kotlin-js-inspection-pack-plugin (0.0.9)
Kotlin: 221-1.6.21-release-337-IJ5591.52
After #PylypDukhov suggestion, trying to update gradle 7.0.4 I am getting this weird error
error
Failed to query the value of property 'namespace'.
Package Name not found in /Users/vmodi/IdeaProjects/abc/src/androidMain/AndroidManifest.xml, and namespace not specified. Please specify a namespace for the generated R and BuildConfig classes via android.namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
settings.gradle.kts
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:7.0.4")
}
}
}
}
rootProject.name = "LetsGetCheckedKotlinMultiplatform"
Added androidMain
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.abc"/>
4.1.2 is android gradle plugin version, it's not related to gradle version.
Android gradle plugin is shipped with Android Studio, if you wanna use latest version mentioned by #Egor, you have to use Android Studio.
IntelliJ IDEA supports them with a delay - the last supported version at the moment is 7.0.4, which works fine to me, the only problem you might have with it is the lack of support for the 32 target version of Android - but it's not required to upload the app and will work fine on 32 devices, also you can build release version in AS with newest plugin, and develop in IDEA, as to me it seems more performant in KMM projects.
4.1.2 is the version number. To find out what the latest version is, visit Google's Maven Repository. At the time of writing, the latest stable version is 7.2.0, so simply replace "4.1.2" with "7.2.0" and rebuild the project.

Failed to resolve : Could not resolve project:MyProject in Andorid Studio 3.0 Canary 4

I am trying to use android studio canary 4 with native java support. But I keep getting the message saying that one of the modules is not found
Error:Failed to resolve: Could not resolve project :MyProject
project :BaseProject
MyProject is present in the directory. It appears in the list of modules in android studio. It is present in settings.gradle. This is a very weird thing that I am noticing. What could be the problem? This is my root build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath gradlePlugin
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
flatDir {
dir 'libs'
}
maven {
url "https://s3-ap-southeast-1.amazonaws.com/godel-elease/godel/"
}
maven { url "https://jitpack.io" }
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://maven.fabric.io/public' }
}
}
I had the same issue, after trying different things I solved it adding the same buildVariants in both modules (library and base project), in my case only had release{} so the library module is like:
android {
...
flavorDimensions "your"
buildTypes {
release {}
}
}
I experienced the same problem like you, but with android modules (instant app), and Alexanders solution doesn't work anymore (but it's the right way), since Beta 4. So I found this other answer on StackOverflow. TL;DR
Instead of buildTypeMatching ‘staging’, ‘debug’ you now specify the fallback inside your buildType node:
android {
...
buildTypes {
...
staging {
matchingFallbacks = ["debug"]
}
Hope this helps!

Gradle build error: Failed to resolve:

I just downloaded Android Studio and created a new project and I'm getting gradle build errors:
Failed to resolve: com.android.support.test.espresso-core:2.2.2
and
Failed to resolve: com.android.support.appcompat-v7:25.3.1
This error was resolved reinstalling the SDK Tools + Repository + API when launching android studio as admin.
I've installed API Level 25 which what I want to build on and have downloaded the SDK Build-Tools. I have also already download the support repository
Here's my app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.jtsalas.mirrorcontrol"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
From the SDK manager, make sure you have both the Android Support Repository and Google Repository installed and up to date. You should then be able to find the relevant artifacts in sub folders of your /extras/android/m2repository directory
From your error it seems that you are not including espresso libraries. The solution to this is adding espresso core library which is part Android Testing support library which is hosted in the google's Maven repository think this as kind of git repository but for dependencies.
So we tell the gradle build system to look in the Maven repository for dependencies by specifying its URL.
This is done by adding Maven url in the application level build.gradle file under repositories block
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
and in the module level build.gradle file mention the dependencies that you want from the maven repository by mention their name as follows:
dependencies{
//other dependencies go here
//testing dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}
That is the reason for including Maven repository url in the app level build.gradle file, hope this helps.
In project.gradle file, the allprojects root align this way:
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
jitpack is used as the dependency for multiple libraries, if you're not using any sort of library that don't requires it then not include maven line.
Well, I don't know the perfect answer but..... how about comparing with my SDK Tools?
I solved it by uninstalling Android Studios and deleting old versions of Android Studios in my C:\Users[Username] and reinstalled Android Studio as administrator.
It seems like you updated android studio and opening previous project in it.The simplest way is create new project and copy
1. compileSdkVersion 26
2. buildToolsVersion "26.0.1"
3. targetSdkVersion 26
4. compile 'com.android.support:appcompat-v7:26.+'
and paste them in appropriate places in app level build gradle.
it will ask to update to take advantages .. allow it to update.
best luck ... It worked for me.
if your project is Flutter,
clean project [by 'flutter clean' command]
In project.gradle file add [ google() ]
in Android studio: File Menu -> Invalidate...
project.gradle:
allprojects {
repositories {
google()
jcenter()
}
}

jitpack.io failed to resolve github repo

I have a Github repo and pushed tags on it.
This is my gradle file of my main project.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "dropbox.ric.es.myapplication"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
//mavenCentral()
//jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.github.rchampa:DropboxHttpConector:1.0.1'
}
But when I sync gradle I have the following error Failed to resolve com.github.rchampa:DropboxHttpConector:1.0.1
Another attempt:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.github.rchampa:DropboxHttpConector:1.0.1'
}
Still failing.
For anyone else that made the simple mistake I made:
Ensure you add the maven { url "https://jitpack.io" } under allprojects instead of buildscript.
Project build.gradle file:
buildscript {
repositories {
jcenter()
// DO NOT ADD IT HERE!!!
}
...
}
allprojects {
repositories {
mavenLocal()
jcenter()
// ADD IT HERE
maven { url "https://jitpack.io" }
}
}
Thanks to Alexander Pacha for pointing that out in a comment above.
Newer versions of Android Studio don't use allprojects anymore.
Open the file settings.gradle and add the repository as shown below:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // <- here we go
jcenter()
}
}
Also remove the code below from the file project's build.gradle, if it is still there:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}}
After a few attempts and thanks to jitpack support now I can import my library hosted in Github as a Android Gradle dependency.
I will provide a a few very useful links:
How setup your java library
https://jitpack.io/docs/BUILDING/#gradle-projects
How check logs of your dependency in jitpack
https://jitpack.io/com/github/USER/REPO/TAG/build.log
In my case
https://jitpack.io/com/github/rchampa/DropboxHttpConector/1.0.3/build.log
I have several dependencies from Jitpack and I encountered this issue after migrating to Gradle 2.
The solution in my case was to change the version in distributionUrl in gradle-wrapper.properties from 2.10 (which was automatically set by Studio when I accepted updating the wrapper version) to the latest one.
Hallelujah I got the problem!
So I realised that PROBLEM is relied on my NETWORK! I can't acces https://jitpack.io/ from my IP that's why nothing was working. Just shared internet from a GSM module(to get a different IP) and problem is gone using #SteveMellross solution
Maybe it can be 0.001% that you have the same problem but if nothing works just try to access https://jitpack.io/ ;)
I hope there is just a firewall or internal router error and my IP is not banned by their service.
Verify that maven { url "https://jitpack.io" } is in allprojects section in build.gradle (Project)
For me I did this
1.Forked the original unmaintained repo
2.Did some changes,created the commit
3.Copied commit hash from commit details page url
eg https://github.com/omkar-tenkale/NavigationTabStrip/commit/9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0
4.Created implementation string from repo url
implementation 'com.github.User:Repo:Version'
Group: com.github.Username
Artifact: Repository Name
Version: Release tag, commit hash or master-SNAPSHOT
More at https://github.com/jitpack/jitpack.io
I used commit hash as Version
implementation
'com.github.omkar-tenkale:NavigationTabStrip:9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0'
5.Now added that in android app module's build gradle
6.But got error Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve...etc
7.Created a link in below format
https://jitpack.io/com/github/USER/REPO/TAG/build.log
In my case
https://jitpack.io/com/github/omkar-tenkale/NavigationTabStrip/9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0/
8.Opened this link in browser
9.Saw something like this
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0-javadoc.jar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0-sources.jar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.aar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom.md5
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom.sha1
build.log
In studio synced gradle again
It worked!
This is far better then downloading repo,importing as module in our app and then using it etc etc.
Whenever you make changes to this forked repo don't forget to update commit hash too!
I meet this problem when I try to import orhanobut/logger from github.
Then I go to jitpack.io and search for the package:
find logger in jitpack
Then I clicked the log icon,and found:
Start: Thu Jan 14 11:56:56 UTC 2016
Git:v1.9
commit 5abbc1563422457d4c23e1a0a412d2b0c7dc334e
Merge: 8ef1e6b 522d44d
Author: Orhan Obut
Date: Mon May 25 11:34:20 2015 +0200
Merge pull request #30 from orhanobut/oo/settings-fix
submodule status:
Run gradle build
Gradle build script
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Downloading https://services.gradle.org/distributions/gradle-2.2.1- all.zip
So this is it,it use gradle 2.2.1-all!
Then I go to my project and change gradle version to 2.2.1 in settings.gradle, everything worked fine!
I'm using Android Studio Arctic Fox 2020.3.1 | Canary 8 and had the issue above.
My repo project is a pure Kotlin project that I want to import into my Android project.
Here are a few steps I did that fixed the issue for me - it could be one of the steps or a combination of them that fixed the issue.
The tag I initially pushed was v0.0.1 but in my build.gradle for the Kotlin project it was version '0.0.1' without the v. So I renamed the tag to 0.0.1 and pushed the tag. #Ricardo's answer above about how to check the JitPack build log was super useful!
Next I ran ./gradlew install on my local machine in the Kotlin repo. This is one of the commands run by JitPack - see the JitPack documentation. When I did this I found this message: Declare the version of Java your build requires.
From that message I decided to specify the Java version. In the Kotlin project build.gradle I added sourceCompatibility = 1.8 and
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
After re-running the command in step 2, the Java version issue disappeared.
I pushed the new version of my Kotlin repo and added a new tag.
In the Android project, I had to add the maven { url "https://jitpack.io" } in settings.gradle. I encountered errors when adding it in the build.gradle files for the app or the root one.
I know this is old but I had this problem recently and I solved it by adding
maven { url 'https://jitpack.io' }
to the settings.gradle(ProjectSettings) under dependencyResolutionManagement{repositories{$HERE}}. I don't know if it is recommended or just a fluke since I am not that well versed yet.

Categories

Resources