I have built an application in Android Studio 4.0.1. The dependencies in my gradle script have all been auto-generated, and I am not sure if they are needed. When I run the app into my phone, it shows a size of 7MB. If I comment the dependencies of the gradle script, the size of the app goes down to 3 MB, and it seems to work the same. Can I just comment those dependencies?
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Yes it is absolutely possible (and you're good to go) if you want to remove UNUSED dependencies. If you end up removing any dependency that you are currently using in your app you will not be able to run your app as it will throw compile error because the compiler won't understand any code that is based on the dependency(s) that you just removed.
For example if you remove the dependency for constraint layout and you have used constraint layout in your project your app won't be compiled. You can google search about any particular dependency to decide whether or not you have used certain dependency on your project.
As you asked in the comments the following dependencies are used for testing your app, if you are not testing your apps you can remove them as well.
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Related
Type com.nikolam.nsdkelper.BuildConfig is defined multiple times: /storage/Users/Volks/Desktop/Android-2020/NsdKelper/app/build/intermediates/project_dex_archive/release/out/com/nikolam/nsdkelper/BuildConfig.dex, /storage/Users/Volks/Desktop/Android-2020/NsdKelper/nsdkelper/build/.transforms/6fff326acaa87110e65737aff5d0e0cd/classes/classes.dex
./gradlew test build outputs this
I have an App Module that implements my LibraryModule and thats it
These are the recommended fixes
This error typically occurs due to one of the following circumstances:
A binary dependency includes a library that your app also includes as a direct dependency. For example, your app declares a direct dependency on Library A and Library B, but Library A already includes Library B in its binary.
To resolve this issue, remove Library B as a direct dependency.
Your app has a local binary dependency and a remote binary dependency on the same library.
To resolve this issue, remove one of the binary dependencies.
These are the dependencies for the two build gradles of the library and the app.
dependencies {
///LIBRARY
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
///APP
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":nsdkelper")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Apps whole build.gradle https://hastebin.com/dehedobica.php
Libraries whole build.gradle https://hastebin.com/omahuqutuc.nginx
I can remove the direct dependency and use JITPACK.io but I'd like to keep it local for development, I tried updating the dependencies, gradle version and downgrading versions but nothing seemed to work. I also deleted some dependencies but that didn't help either. I invalidated cache and similar common fixes but no luck.
I tried removing the dependencies from the App module and just implementing the Library(NsdKelper) but it doesn't work like the way I think it does. My way of thinking is
A implements project B which means that A will check B's dependencies and use those. But that doesnt seem to be the case here. Removing the dependencies from my App Module gives me errors of missing libraries. Or I am I misunderstanding something
They had the same Package ID, renaming the package on one of the modules solved it.
I want to create an application which use some of the framework APIs. I have set the android:sharedUserId="android.uid.system" in AndroidManifest.xml.
In order to avoid reflection, I have imported the framework.jar
The apk is platform signed and I successfully installed the app.
However when I launch the app it crashes. The exception is
java.lang.ClassNotFoundException. It is unable to find the MainActivity.
Another exception is java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.app.AppCompatActivity".
I wish to know whether the framework.jar supports Kotlin and Android Jetpack libraries.
Gradle dependency:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
implementation files('libs/framework.jar')
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Add those two lines to your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
Try to add / change below line to your app/build.gradle
// implementation "androidx.core:core:1.0.2"
// use below kotlin dependency
implementation "androidx.core:core-ktx:1.0.2"
I am really new to android dev (C/Python engineer), and I am looking to include a package from github where it says download the package using:
api 'com.otaliastudios:cameraview:2.0.0-beta04'
I have spent 2 hours looking WTF this api tool is but for the life of me, I cannot seem to figure out what it is.
My dependency block looks like so:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.otaliastudios:cameraview:2.0.0-beta04'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
As you see, I have added the:
implementation 'com.otaliastudios:cameraview:2.0.0-beta04'
and synced the project with gradle files and I still get unresolved reference
According to the documentation try to add:
api 'com.otaliastudios:cameraview:2.7.2'
For more information visit, https://github.com/natario1/CameraView
When add firebase in
dependencies
implementation 'com.google.firebase:firebase-core:16.0.6'
Or
implementation 'com.google.firebase:firebase-ads:17.1.2'
Or
implementation 'com.google.android.gms:play-services-ads:17.1.1
It shows error under implementation 'com.android.support:appcompat-v7:28.0.0' that All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes).
When I sync the app no error but when install the app it shows you app has been stopped (Crashing during run time).
When remove the firebase dependencies and run, my app it's working fine.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-ads:17.1.2'
implementation 'com.google.android.gms:play-services-ads:17.1.1'
}
apply plugin: 'com.google.gms.google-services'
When you include dependencies, they too, will sometimes include dependencies of their own. Some of the firebase libraries happen to include support libraries at a lower version than 28. When you hover over the error message for appcompat-v7 it should tell you what library is lower than 28. You may have to click 'show more' on the error message. Once you figure out which one it is, include that exact same library but version 28. Resync your gradle and you're good to go. Also, you might have to do this multiple times because some firebase libraries include multiple lower version support libraries and the error message will only show you one library at a time.
I just got the android studio and all I did was connecting with the firebase. But I was not able to fully connect because of the appcompat error. I have attached the photo of what I'm getting.
dependencies {
implementation fileTree(dir: 'libs',include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0' <--------------getting error here
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:11.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Error
Dependencies
I look at your error message and it felt familiar as i had received same message so many times!
Root cause is mixing version numbers in dependencies. it seems that in your dependencies you have version 28 and version 25 mixed up. go to build.gradle and put cursor on version number on each of your dependancies and then press ALT+ENTER. go with what android studio suggests and then clean->rebuild. it should work.
Hope this helps!