Stetho-Timber library issue with new Timber version 4.1.2 - java

While I was trying to use stetho-timber Library in my Android application I faced this problem:
Error:Module 'com.facebook.stetho:stetho-timber:1.3.1' depends on one
or more Android Libraries but is a jar
What's wrong?!

After inspecting in its codes I found that it uses timber v3.0.1!
Just add this to your build.gradle dependencies tag to exclude timber within the stetho library,
cause it is an old version and conflicts with new one:
dependencies {
compile ("com.facebook.stetho:stetho-timber:1.3.1") {
exclude group: "com.jakewharton.timber", module: "timber"
}
.
.
.
I have recently found Facebook Stetho Library and using it is fantastic, give it a try! :)

Related

Use a Library in the processor's generated classes

I'm developing a library to generate classes using annotations and processors. The generated classes should use Gson library from google.
My question is : Where should I add the Gson dependency ? I'm currently adding it into the processor build.gradle but when the classes are generated, Gson is not found and Android Studio is suggesting to add it to the app module.
build.gradle of the processor :
implementation project(':lib-annotation')
implementation 'com.squareup:javapoet:1.9.0'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'com.google.auto.service:auto-service:1.0-rc3'
build.gradle of the app :
implementation project(':lib-annotation')
annotationProcessor project(':lib-processor')
Any help would be greatly appreciated, thanks!
P.S. The project is meant to be a library. I expect the users to only include my library in their gradle file, not the "sub dependency".
Simply using implementation prevent you from using transitive dependency.
The main project can't use or invoke the dependencies you added to your library.
As reminded to docs the implementation configuration should be used to declare dependencies which are internal to the component.
So you have to use api OR compile instead of implementation or add a condition to your transitive library e.g :-
implementation ('com.google.code.gson:gson:2.8.1'){
transitive = true;
}
Besides the fact implementation hides the dependency and therefore keeping it out of the app's path (so if you need to expose Gson, avoid using implementation), the problem is due to being compiling/implementing the library module instead of using a regular aar/jar/apklib package. Try this:
-Add the Android Maven Gradle plugin to the library project and configurate it.
-Using the plugin, compile and install the library into your local maven repository.
-instead of using compile/api/implementation for adding the library to the app, include mavenLocal() into your build.gradle, and then add the library as a regular dependency. All the necessary dependencies should be there.
here's an example of the plugin, in case you need it: https://github.com/fcopardo/EnhancedMapView
follow this link, I have imported without any problems.
http://blog.madadipouya.com/2015/09/21/how-to-add-gson-library-to-android-studio-project/
Okay, I finally fixed the problem!
I had to add the Gson dependency into the processor build.gradle using implementation or compile :
implementation 'com.google.code.gson:gson:2.8.1'
And add the dependency again into the annotation build.gradle using compile :
compile 'com.google.code.gson:gson:2.8.1'
I think it wasn't working because the Gson dependency was in the processor build.gradle which is included using annotationProcessor 'lib-processor' (Somehow the "transitivity" wasn't applying). Therefore I put the Gson dependency in the annotation build.gradle since I include it using implementation 'lib-annotation' and it worked.
Hope it will help

Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: on path: DexPathList

how are you ?. i've searched this question carefully but there seems no complete answer as to why and how to solve this issue.
okay, at first i am running Android Studio 1.5.1 with completely out dated gradle and sdk version but at that time i felt enough to use those old versions but now i updated all of those to android 2.3.1 latest SDK and latest Gradle.
as you may already know if i run directly from Android Studio it works fine, but when i copy my app_debug.apk file it suddenly showing the error
Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.asd.asd.asd1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
i've applied many solution to this particular error, one which being successful was changin my gradel version in modul:app gradle from
classpath 'com.android.tools.build:gradle:2.3.1'
to
classpath 'com.android.tools.build:gradle:2.2.3'
but then i tried all other app that i've made before and applying the same method. strangely, it didn't work.
and i think there is something that i am missing here but i dont know what, i dont want to enable multiDexEnabled because i dont think that's a good way to solve this problem.
thanks.
what you have to do is enable Multidex in gradle
defaultConfig{
multiDexEnabled true
}
else you need to minimize the use of heavy dependencies. if you insist to use those dependencies, you need to exclude module android support module in those dependencies..
for example, i already have appcompat-v7 in my list. so exclude module appcompat-v7 from third party library.
compile ('uk.co.chrisjenx:calligraphy:2.2.0'){
exclude group: 'com.android.support', module: 'appcompat-v7'
transitive = false
}

how can i download AppCompatActivity librery for ADT

I have a problem with importing the package :
"import android.support.v7.app.AppCompatActivity".. i think because i should
download AppCompatActivity librery before importing it
Please, how can i download AppCompatActivity librery??
[1]: https://i.stack.imgur.com/mMPQs.png
No need to download it separately.You can fix it updating your "build.gradle(Module:app)" file. in order to do it you need to add your compiler dependencies for project.
Add this line to "build.gradle(Module:app)" file
compile 'com.android.support:appcompat-v7:25.3.0'
then Sync your project and make sure network connection is working.That's it :)
bellow is an example that shows where you add a compiler dependency to your project.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espressocore:2.2.2',{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.0'
testCompile 'junit:junit:4.12'
}
To Setup Android Support Library :
The Android Support Repository package is provided as a supplemental download to the Android SDK and is available through the Android SDK Manager.
Follow the instructions below to obtain the Support Library files.
To download the Support Library through the SDK Manager:
1.Start the Android SDK Manager.
2.In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.
3.Select the Android Support Repository item.
4.Click the Install packages... button.
Then After Downloading,
Adding Support Libraries
In order to use a Support Library, you must modify your application's project's classpath dependencies within your development environment. You must perform this procedure for each Support Library you want to use.
To add a Support Library to your application project:
Make sure you have downloaded the Android Support Repository using the SDK Manager.
Open the build.gradle file for your application.
Add the support library to the dependencies section. For example, to add the v4 core-utils library, add the following lines:
dependencies {
...
compile "com.android.support:support-core-utils:25.3.1"
}
Then you can use your Support Library elements.

Exclude Package From Gradle Dependency

I'm experiencing an issue where multiple versions of the same class are showing up in my classpath. The class in question is javax.ws.rs.core.UriBuilder. The version I want to use is brought in by javax.ws.rs:javax.ws.rs-api:2.0.1. However, we also use the Jira rest client library which has a dependency on the older version of jersey (com.sun.jersey:jersey-core) which has included the java.ws packages bundled in it's jar.
Here is an example snippet from the build file:
dependencies {
compile 'com.atlassian.jira:jira-rest-java-client-core:2.0.0-m31'
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
compile 'org.glassfish.jersey.core:jersey-client:2.17'
}
I can't remove com.sun.jersey:jersey-core as it uses different package name from the new version and would cause class def not found exceptions in the Jira client.
As far as I can tell, my options at this point are:
Revert to using Jersey 1.x and it's implementation of jsr311
Somehow have gradle exclude the javax.ws package from the old jersey client.
I'd like to keep using the newer version of jersey so #2 would be my ideal solution but I'm not sure if it's even possible. Does anyone know how to go about this? If that's not possible, I'm open to other suggestions.
You can exclude an transitive dependency module like this:
compile ('org.glassfish.jersey.core:jersey-client:2.17') {
exclude group: 'javax.ws.rs'
exclude module: 'javax.ws.rs-api'
}
ref: 50.4.7 here
I found out that com.sun.jersey:jersey-core:1.19 doesn't bundle the javax.ws.rs class files and instead lists them as a compile-time dependency. Adding this snippet to my build.gradle fixed the issue.
configurations.all {
resolutionStrategy {
// For a version that doesn't package javax.ws
force 'com.sun.jersey:jersey-core:1.19'
}
}
exclude the group and module as below.
Ex :
implementation('org.apache.httpcomponents:httpclient:4.5.13') {
exclude group: 'commons-codec', module: 'commons-codec'
}

multiple dex files define landroid/support/annotation/AnimRes

The moment I added the android support annotations to my dependencies
compile 'com.android.support:support-annotations:20.0.0'
I got this error:
Error Code:
2 Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
build.gradle
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.android.support:support-annotations:20.0.0'
}
Anybody else experienced this issue? I have tried the solutions from here.
The problem is that android-support-annotations.jar used to be a separate library containing the android annotations, but for some reason these annotations are already included in recent versions of the android-support-v4.jar file.
Deleting the annotations jar solved the issue.
Build->clean Project ,and it worked
I deleted the android-support-v4.jar and it worked.
If this is cordova / ionic project this worked for me
add these line to build.gradle under platforms/android after line number 22 i.e after apply plugin: 'android'
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
Solved this exact issue in a Cordova project that used the facebook plugin. I was able to successfully build by commenting out this line from platforms\android\project.properties, as shown:
# cordova.system.library.1=com.android.support:support-v4:+
And by commenting out this line from platforms\android\build.gradle, as shown:
// compile "com.android.support:support-v4:+"
Then doing the build. The problem started when I installed (katzer/cordova-plugin-local-notifications) which added these lines, but it created a conflict since the library it was adding to the build was already part of the facebook plugin build.
As other users said, the first elements to troubleshoot are dependencies. Although, sometimes you can struggle for hours and you don't find any problem so you can focus on the build process instead.
Changing the way in which the .dex files are produced sometimes solves the problem. You can go through these steps:
Open your Build.gradle (app) file
Search for the task dexOptions
Change it to:
dexOptions {
incremental false
}
If you don't find the task in your file then you can add it.
For me the reason was the new data-binding lib
com.android.databinding:dataBinder:1.0-rc2
it somehow used a conflicting version of the annotations lib, which I could not force with
configurations.all {
resolutionStrategy {
force group: 'com.android.support', name: 'support-v4', version: '23.1.0'
force group: 'com.android.support', name: 'appcompat-v7', version: '23.1.0'
force group: 'com.android.support', name: 'support-annotations', version: '23.1.0'
}
}
but the new rc3 and rc4 versions seem to have fixed it, so just use those versions
I had the same problem , but i deleted build files from the build folder
projectname/app/build
and it removed all the related error. "can't clean the project" and also "dex errow with $anim"
I managed to fix this issue. The reason was that I included the android support library 19.0.0 as a dependency, but 19.1.0 is required. See here for more information
So it has to be
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.android.support:support-annotations:20.0.0'
}
If you import AppCompat as a library project and you also have android-support-annotations.jar in libs elsewhere, make sure to import everywhere AppCompat library only (it already includes this annotations lib). Then delete all android-support-annotations.jar to avoid merging multiple versions of this library.
Updating Android SDK Tools fixed it for me, now it just sees the copy in android-support-v4.jar.
I had the same problem when using ant, and the annotations library was being included automatically by an outdated sdk.dir/tools/ant/build.xml.
Clean project works as a temporary fix, but the issue will reappear on next compilation error.
To fix more reliably, I had to update the dependency to android support-v4 to com.android.support:support-v4:22.2.0.
Put in your build.gradle the dependency of support-annotations according with your compileSdkVersion. For instance: A project with the compileSdkVersion 25 you can put the following dependence:
compile 'com.android.support:support-annotations:25.0.1'
This will solve your problem.
In my case I had a file called cache.xml under /build/intermediates/dex-cache/cache.xml in the root project folder. I deleted this file, rebuild the project and it worked for me.
I deleted the android-support-v4.jar and it worked.
Explain - android-support-v4.jar is conflicting with my other .jar files of project\libs files ** specially when you are running with java 8 on AS.
Put android-support-v4.jar in your libs folder in eclipse. Clean and build the project. It will resolve the issue.
Another reason that messages such as these can come up in Android Studio when building and launching can be the cause of application tags in your libraries.
If you have several Android Library projects that you imported as modules. Go into those projects and remove the <application> ... </application> tags and everything between them. These can cause issues in the build process along with the support library issues already mentioned.
From /platforms/android/libs/
delete android-support-v4.jar.
It works for me.

Categories

Resources