Duplicate class androidx - android-studio

I'm trying to add a Bottom Navigation Activity to my project in android studio but when i run the project I get an error
Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
Duplicate class androidx.lifecycle.ViewTreeViewModelKt found in modules lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
I tried adding "android.enableJetifier=true" to gradle.properties file but it still gave me the same error.

Related

Android Studio : Cannot use class from src in Unit tests

since the last Update (of Android Studio ? or Gradle ?) I cannot import code from prod in my tests classes.
A few months ago, the tests were working without any problems.
I can launch the tests, using gradle in command line, or using AndroidStudio test runner. And it work nice : it passes when the code is ok, it fails when there is a bug.
But the auto-completion isn't working, the class, methods ... are red.
I cannot click on an object to navigate to the declaration ... and so on.
And the AndroidStudio automatic quickfix is : "add dependency on module xxx"
which add a line in the gradle file :
implementation project(path: ':app')
I have the same problem on several project, with gradle 6.1.1 or 7.2.1
AndroidStudio version is :
Chipmunk, 2021.2.1 patch 1
built on May 18 2022
the unit test, in app/src/test/java/com/apackage/ASimpleTest.kt
package com.apackage
import org.junit.Test
import kotlin.test.assertEquals
class ASimpleTest {
#Test
fun aTest(){
val plop = AClass()
assertEquals(1, plop.aMethod())
}
}
the class in app/src/main/java/com/apackage/AClass.kt:
package com.apackage
class AClass {
fun aMethod() = 1
}
I have no problem calling a method in the same folder as the tests.
The problem is test/main folder calling src/main

How to build custom Capacitor 3 plugin and access Java class from another plugin in node_modules

I am building a custom capacitor plugin with:
npm init #capacitor/plugin
This creates my plugin but following the directions it says to run:
npx cap sync
But I get this error: npm ERR! could not determine executable to run
I'm just adding this info as I'm not sure if it affects anything...
So I created my Java class in Android studio (AS) to extend capacitor-push-notifications. All this works in AS but I wanted to create a plugin so if something happens to the android folder I can rely on my plugin to add the Java files.
I import the file (in Java):
import com.capacitorjs.plugins.pushnotifications.PushNotificationsPlugin
My question is: How do I import the capacitor-push-notifications when I am in VS Code? I get the following error when I run npm run verify:android:
Could not find com.capacitorjs.plugins.pushnotifications:pushnotifications:1.0.9.
Required by:
project :
also, I did install the plugin:
npm i #capacitor/push-notifications
also added this to build.gradle under dependancies:
implementation "com.capacitorjs.plugins.pushnotifications:pushnotifications:1.0.9"
So do I just ignore the error as I know it works in AS? I looked everywhere and cannot find any reference to this.

Android Studio 3.1.1 - unable to add module (import gradle project)

Android Studio 3.1.1. New module -> Import gradle project, after I select project to import and confirm, IDE crashes with exception:
Element: class org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl because: different providers: SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(1416c50); SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(665cfacf)
invalidated at: see attachment
com.intellij.psi.PsiInvalidElementAccessException: Element: class org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl because: different providers: SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(1416c50); SingleRootFileViewProvider{myVirtualFile=file:///home/michal/AndroidStudioProjects/FirebaseJobTest/settings.gradle, content=VirtualFileContent{size=26}}(665cfacf)
invalidated at: see attachment
at com.intellij.psi.util.PsiUtilCore.ensureValid(PsiUtilCore.java:502)
Do you know any workaround?
I was facing the same issue, seems like IDE issue, try manually adding
include ':app', ':your_module_name'
in settings.gradle and sync gradle, hope it helps.

A library uses the same package as this project

For 2 days, I have been trying to fix my Android Studio setup, but despite a lot of googling have had no luck fixing this problem. Gradle keeps giving me the error
Error:Execution failed for task ':Android-Tabbedout-30:processQaReleaseResources'.
Error: A library uses the same package as this project
You can temporarily disable this error with android.enforceUniquePackageName=false
However, this is temporary and will be enforced in 1.0
If I add in the enforceUniquePackageName=false to the gradle file, then the project can be successively refreshed by Gradle, but once I try to run it I get this error:
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define
Any ideas on how to fix this?
I was searching for that same problem and i find this on github
https://github.com/DWorkS/AStickyHeader/issues/12
And this solved my problem.
All this says is to rename the package name on the AndroidManifast.xml file.
And its done.

Android Studio Google Play Services no autocomplete

I use AS 0.4.2 then imported GMS as described in doc:
https://developer.android.com/google/play-services/setup.html
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v13:13.0.+'
compile 'com.google.android.gms:play-services:4.0.30' }
all what is detected by IDE is R class, but rest of code is invisible.
On the other hand I put following code:
import com.google.android.gms.common.GooglePlayServicesUtil;
(...)
private void connectGms(){
Log.d(MbcConstants.TAG,
"check for gms"+ GooglePlayServicesUtil.
isGooglePlayServicesAvailable(this));
}
And it works, but IDE still shows class name in red, but properly shows the params and returned type for method.
Ok - it seems like a bug in Android studio.
What I've done do fix it:
remove all dependencies (use F4 key) from project and the module
delete files from projectroot/.idea/libraries
open the module gradle.buld
add back all dependencies that are needed by your project to work. In my case:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
}
Synchronize gradle.build once again
Continue your adventure of love and hate or return to eclipse.
All you needed to do was hit the Sync Project with Gradle Files button after editing the build.gradle file by hand.

Resources