Android studio can't edit library - java

I downloaded this library and i extracted the rar into my app\libs folder.
Then I added compile 'com.github.lzyzsd:circleprogress:1.1.0#aar' to my build gradle as it says, and clicked on sync.
Then I noticed that the max is set to 100 (in file DonutProgress.java).
I changed it to 5, clicked on sync again but nothing changed.
After few hours of trying I decided to completely remove the extracted folder from my app\libs and sync again to see what happens.
Surprisingly, everything was still working like library was still there.
Can someone explain me what's happening here, I have to edit it but it seems whatever I do to the library doesn't affect the app.
It seems like it's using another library from totally different folder, I don't know, I tried searching for DonutProgress on my computer but didn't find anything that seems useful.
Please help.

When you add compile 'com.github.lzyzsd:circleprogress:1.1.0#aar' to your build.gradle dependencies, you are telling Gradle to go fetch this library from a repository when you build.
For most Android apps, this means that when you do a build, Gradle will go and download the library (in this case a .aar) from jCenter. This is good because it means you no longer need to manage the JARs (or other library files) yourself.
If you want to use a custom version of that library, then you should not add that dependency to your Gradle build script. Instead you should add it as either a module or a local dependency (e.g. compile files('libs/custom_library_name.aar')).

Related

Unable to merge dex after adding a third party .aar file

I am running into the unable to merge dex problem that many posts seem to complain about. After doing some research, I think I have found the source of the problem, but I don't know how to proceed to fix it.
I am currently putting together various third-party components to create an Android application. It consists of the following parts:
app: The app itself, which is a minimal app with a Kotlin Activity created from Android Studio
libs: Two .aar files, A.aar and B.aar, where A.aar depends on B.aar
base: A third-party java module which provides some interfaces, helper functions and includes some dependencies for them. This module has its own build.gradle file.
I integrated them following these steps:
If I add base as a dependency of app, everything builds
When I add A.aar as a dependency in the app's build.gradle, it still builds
Then, when I add B.aar as a dependency for the app (implementation B.aar), the gradle build fails with the error: Unable to merge dex.
Looking at the Gradle stack trace, I found that it is complaining that multiple dex files define Lcom.google.common.io.ByteSink, which appears to be Google's Guava library.
Using the Project view in Android Studio, B.aar appears to actually contain version 18.0 of Guava inside it (under a 'classes.jar' section). I think this conflicts with base's implementation dependency line for guava 20.0 in its build.gradle.
Thus, I think I have found the source of the conflict (2 different versions of guava colliding), but I am not sure how to proceed. Was the third party wrong to have packaged guava into the .aar? If so, do I have any means of working around this problem other than asking the third party to remove it?
Things we have tried and did not work:
using exclude statements in the implementation statement that includes the AAR (I suspect it may only work with external dependencies, not with code that is built into the AAR)
using preDexLibraries (true worked for some of us, false worked for others -- it's not a solution!)
I'm more of a C++/C guy, so I may need a bit of hand holding with Java-specific concepts. I thank you in advance for any help.
The only solution we found was to do the following to the third party AAR:
Open the AAR file with a .zip file editor (ex: 7-zip)
Open classes.jar within the AAR
Navigate to the com directory
Delete the google subdirectory
We then added guava as a dependency in the gradle file
It works, it's the right thing to do, and we are pending an ok from our third-party provider.

Change Arr file then include it in Android Studio

I got some arr file that I need to change. It is https://github.com/BlinkID/blinkid-android library and I need to change something in xml file (values directory) to make it work and include it in my project in Android Studio. This is what I did ( I tryed other ways too but without success):
Changed arr extension to zip
extracted it with WinRAR
made changes to xml
Packaged it again and changed to arr extension again
In android studio I went File->New->New module->Import JAR/ARR Package.
If it is not added automatically I would add compile(:LibBlinkId) to gradle
Unfortunatelly when I start typing com.microblink... I don't get intellisense, meaning that library was not added. Also I tryed to rename it to .jar file, then added it to libs directory and go to : File->Project Structure-> selected my app module and added that jar, then in gradle I put something like compile files('libs/LibBlinkID.jar')
That did not help also.
After changing your build.gradle you should also do a Sync Project with Gradle Files.
If there were no errors during this step, I see no reason why your method wouldn't work except for the fact that on step 6 it should be:
dependencies {
compile project(':LibBlinkId')
...
}
If Android studio somehow failed to sync up to your dependencies you might want to try an Invalidate Caches / Restart from the File menu and follow that with a project rebuild.
Update:
If that still does not work but the project builds successfully, try to manually import a known class from the AAR and to use that class in a small piece of code. Then run your app.
When dependency import failures happened to me, after such a manual step Android Studio autocomplete would start to work and give me the correct suggestions.

After creating android project in Eclipse ADT, tons of errors show up

I'm using eclipse ADT (most recent version) to develop some android apps. I've followed the getting started tutorial at the dev.android.com and it worked just fine.
But when i tried to create another project with the same targets and sdk's, i've got nothing but errors:
Some errors and my sdk's:
That's the same sdk's i used before these errors started showing up.
What can be causing this?
EDIT: my project won't generate the R.java file
You might need to add a support library to your new project.
Check this link for downloading the support libraries -
http://developer.android.com/tools/support-library/setup.html#download
Please notice that you need to import them into your eclipse and then include one (preferably the newest, not sure about this) in your project.
EDIT:
Before downloading the support libraries you should first check if you have them already.
Try this, right click project folder in the eclipse package explorer, Properties>Android>Library>Add>select a library if you have one.
There might be an invalid library included in your project already, if that happens then you will see it in the Library>Add> menu, remove it and add a new one.
You might have clean your project ........
if yes.....you must check whether R.java file is present in **Project(your project)->gen->package name->R.java**
if not than u have to update Tool Folder in SDK manager

android-support-v7-appcombat jar mismatch and app crashing after Android 4.4 SDK update

I have been successfully using android-support-v7-appcompat library for last few months in my app to support action bar in older devices. Recently I have downloaded the Android 4.4(kitkat) updates with system image and SDK platform from the SDK Manager. I also added targetSdkVersion to "19" in manifest file. But my project was showing error as 'android-support-v7-appcompat jar mismatch. Fix your dependaecies.' Then I added the jar from /extras/android/support/.... to the project as an external jar using build path menu > add external jar. Now there is no error in the project and android-support-v7-appcompat.jar & android-support0v4.jar file is showing twice under 'Referenced Libraries' folder and also once under 'libs' folder. The project is not showing error and running, but crashing in different activities.
Previously I imported the android-support-v7-appcombat library as an external project in the workplace. I can see error in that project. Please suggest what should I do now. Also, android-support-v7-appcompat.jar umder Android Dependencies in Java Build Path showing error.
The error I see is:
Found 2 versions of android-support-v7-appcompat.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
Versions found are:
Path: C:\<project hierarchy>\libs\android-support-v7-appcompat.jar
Path: C:\Users\....\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar
Jar mismatch! Fix your dependencies
After getting idea from different forum, I removed all the android-support-v7-appcompat libraries from different places, and imported android-v7 support library again in the project. Still it's showing error. Should I also delete android-support-v4 libraries from buildpath and libs/private librariry/referenced library folders?
This error occurs when there are multiple and different instances of the same library are found in the same project, or libraries used by it. A very simple way to resolve this is use the common lib at both the places. To do so:
Just copy your C:\Users....\AppData\Local\Android\android-studio\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar
and paste it in your libs folder, replace the old one with this. Clean the project, and it shall compile now..
Edit 1:
Basically the idea is if you are using the same libraries, it shall be the common jar, or the same jar.
In your case if you are using the appv7 as an external project, please go to libs folder of your project copy android-support-v4.jar, and paste into the libs of android-support-v7-appcompat project.
Also, make sure if there are other external jars or support libraries used by you, they shall be the similar jars in all the projects you are using.
I hope it helps!
I had exactly the same problem after installing all the updates mentioned in the question. I am sure there are different ways to solve this problem. Here is the way I used:
Previously, when an activity was created, the following project was automatically generated by the wizard:
androi-support-v7-appcompat and this project was added to the build path.
After all the updates, the following equivalent is generated when an activity is created:
appcompat_v7 with the jars of the same names.
I deleted androi-support-v7-appcompat and made sure the projects use appcompat_v7 to replace androi-support-v7-appcompat in their build paths. This made hundreds of errors generated by the duplicates go away.
I am glad that i finally found the answer. I was encountering the same problem again and again and i was like fed up.
Here is the answer to your question.
whenever you get such an error just don't touch anything other than libs folder. Just go directly into the libs folder and right away delete the android-support-v4.jar. and clean build your project. You will be relieved to get rid of errors.
Hope its useful to you.
Keep coding..
I have actually figured out the solution by trying different options suggested from different forum. I had manually change the android-support-v7-appcompat project's(which was added as an external project) project.properties file and had to set 'target=android-19'.

Netbeans 6.8 Tree & editor hints not in sync with build

I'm having two nb-projects.
One nb-project(a) has the other nb-project(b) as a library dependancy.
Now both nb projects compile/build fine, but the hints for (a) are out of sync.
This interferes when i want to run/debug saying 'one or more projects were compiled with errors'
I've tried
opening/closing both projects and recompiling
scan for external changes'
clean-build, removing the 'compile on save' flags for both projects etc.
en/disabling 'Build Jar after compiling' for the jtools project.
Removing the :
./netbeans/6.8/var/index
directory only made things worse for the nb-project(a)..
Now exclamation marks for all imports of packages from nb-project(b)
But still compile/build worked fine.
Even unit-tests within the same netbeans project in(b) didn't even recognize the root-package ?!
After some strugling its a bit better, but hints are still not correct in (a).
Now in (a) it says one method doesn't exist in project(b), but i've looked it up in the build-jar of (b).. it's there !?
Any ideas how to get the hints back on track?
Thanks
I've seen something like this when I upgrade a library but neglect to remove an earlier incompatible version from a path visible to NetBeans. Older JARs carelessly left in an extension directory are particularly troublesome, especially if they alias new entries you've added elsewhere. Also, review the Tools > Libraries dialog entries for duplicates and errors. Finally, check each project to be sure it's using the required libraries.
There are three ways to create dependencies in NB. You can add a project, add a library, or add a jar/folder. Only the "Add Project" button tells NB that the dependency is mutable. The other choices (Library and Jar/Folder) expect the jar will never change.
Try deleting the dependency on project(b), then add it back using the Add Project button.
I only use the Add Library for stable, third-party libraries (apache commons for example). I only use the Add Jar/Folder for third parties libraries I know I won't use anywhere else. Such as vendor libraries for communicating with a particular device.

Categories

Resources