Sorry if this question is duplicated but I have searched for a while and couldn't find the answer.
I use Android Studio and Gradle to develop my app, gralde will auto download source code from maven but then inside Android Studio it's said that "Sources Not Found" and I have to drag drop or select the source files directly. This is very troublesome. Is there anyway that AS auto link the sources downloaded with the class, and when I ctrl + click on the class it will open the source file directly?
Edit: Some libraries like ButterKnife I can view source code directly, but others like MaterialEditext I have to select the source file manually.
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.rengwuxian.materialedittext:library:2.0.3'
ButterKnife can be found in External Library while MaterialEditext isn't. I don't know why.
Not every module you want can be selected automatically. Only those you can find in dependencies could be imported by Gradle. Take a look here:right-click at your project --->Open Module Settings--->Modules--->Dependencies--->Plus--->Library Dependency, and then you can select one Library Dependency. And then it will be added into your project by Gradle. Most importantly, What You Can See Is What You Can Get. If you can't see the module you want, maybe you need to download it somewhere else.
Related
I have a set of utils and custom widgets that I want to pull out of my project as an Android library so that I can use them in other projects (and possibly share in the future). I created a new Android Studio project and changed the build.gradle file so that 'com.android.application' was 'com.android.library' and deleted the applicationId. It all compiles fine and I have a .aar file created.
I now want to use this new library as a module in my original project. When I do an Import Project, all the files from the library project are copied into my original project. But I don't want that because if I change the imported library code, it isn't reflected in the library project or vice versa.
I also tried adding this to settings.gradle:
include ':myutils'
project(':myutils').projectDir = new File(settingsDir, '../../../../Development/MyUtils/')
and in the original project app build.gradle:
dependencies {
implementation project(':myutils')
...
But I get this error:
ERROR: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve project :myutils.
Show Details
Affected Modules: app
How can I link the library to my project without importing it? I would prefer not to go through an external maven repo yet. I'm happy to (and would expect to) recompile my library whenever there is a change there and then rebuild my original project.
Thank you in advance.
I think I just had the same problem - I wanted to put the library .aar file somewhere on my local drive and then use it in a new app as a dependency. I didn't want to have to go through a repo or to include it in the libs folder in the new app. Hopefully that is what the OP asked and the following might be of help to others.
Searching on SO (Aug 2021), majority of answers seemed much more involved than what Android Studio offers (tested on version 4.2). That is, an .aar file that lives outside the app project can now be added as an implementation file in the gradle dependencies. So, it doesn't have to go through a repo, and it doesn't have to be included in the libs folder in the project.
The current documentation (Aug 2021) gives a fairly straightforward answer how to do it:
https://developer.android.com/studio/projects/android-library#psd-add-aar-jar-dependency
In short, if you have put your .aar file somewhere on your local drive, this is how to add it as an implementation file in another app project:
In Android Studio, in your new app project, go to: File > Project Structure > Dependencies.
In: Modules > app > Declared Dependencies, click '+' and select 'Jar Dependency'. (Even though you are trying to use an .aar file, you still select 'Jar Dependency').
In the 'Add Jar/Aar Dependency' popup dialog:
in step 1 enter the path to your .aar file on your local drive, and
in step 2 select 'implementation'.
If everything worked out, your build.gradle(Module) should have a line in the dependencies that looks like:
dependencies {
implementation files('../../../MyFolder/MyLibraryFile.aar')
A few notes:
You can actually just add the dependency manually, by typing it into the build.gradle(Module) dependencies, so you don't actually have to go through the Android Studio dialog outlined above.
you can either use a relative path (as the example above), or an absolute path.
the Android Studio dialog is somewhat limited in that you cannot just browse to your file (in point 3, step 1), but you have to actually enter the path manually.
Probably the most important: Whenever you make a change in the library and assemble a new .aar file, then remember to do the following in your app project that uses the .aar file as a dependency: Clean Project, then Sync Project with Gradle Files, and only then run the app, so that the changes in the library could take effect in your app.
I have been using Phgr's above technique for four years. I have three comments -
First, I don't clean the app project each time I change the library - I just do a Sync Project before building and testing the app.
Second, I changed the File-Settings-Keymap-Main Menu-File-Sync to Alt-S for easy of syncing - I hate wasting time using the mouse for selecting the Sync icon.
Third, I have an implementation line in the app's build module file for each app variant such as the following -
debugImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-debug.aar')
releaseImplementation files('c:/Android Studio Projects/PciLibrary/app/build/outputs/aar/PciLibrary-release.aar')
All of this is working fine with Android Studio 4.2.2 and sdk version 30.
Hope this helps others with this problem
I am new to android, and I started a project in android studio.
I found an interesting animation, which I would like to use, and perhaps edit in my project, it can be found here https://github.com/booncol/Pulsator4Droid
Now I wonder, how can I use this? I find the description on github hard to understand, I know that AS uses gradle to build, but where in the gradle file should I add the compile? And should I download some additional java files? And should I change my xml files?
I tried searching SO for answers, but one of the most relevant answers was about downloading a jar file, but there is no jar file to download in this case!
Thanx in advance.
You should add the compile line to your module gradle (under the mobile app folder) dependency section, something like this (ordering of the dependencies doesn't matter)
dependencies {
... other stuff may be here
compile 'pl.bclogic:pulsator4droid:1.0.3'
}
This will automatically download the java jar files required when you build.
Then where you want to use the pulsar control just add it to your activity xml file as specified in the projects readme under the usage section.
Add compile 'pl.bclogic:pulsator4droid:1.0.3' this in your app level gradle file
My problem is adding a library to my project in Android Studio. In module dependencies I'm gettin this weird thing. Any help will be appreciated.
Here is the pic:
android libraries are usually come as links to sources not as jars or some other type.
Take a look at the image. Do you see that there are actually 2 build.gradle files? what you need is the (Module:app) gradle build file select that and paste the link in the dependencies part in the bottom of that file just like what i have done , then Android Studio will ask you to sync the file. Do it. It will download the dependency from your link provided and integrate with the project
Hope this helps..
I want to include the guava-07.jar in my project.I tried configuring build paths,copying it to library folder,linking source and used add external jars.
The import com.google.common.eventbus.Subscribe cannot be resolved keeps showing.
I have a project with guava.jar in its private library.Can I put that in this project.Or is there another problem.Please help me understand.
after referring some questions in stack and in google, i got something like this hope these may help you
as you have done before just remove all your dependencies and add build path and clean project once if it dint work just go through the things
The easiest way to deal with such a library in Eclipse is to create a User library and add the user library to your project (right click project: Build Path -> Add Library -> User Library).
Here is a short guide to generating a User Library:
Open the menu entry Preferences -> Java -> Build Path -> User Libraries
Press New..., enter a name (e.g. 'Guava')
Press Add JARs... and search for the JAR files you downloaded
(Unzip the Guava archive beforehand, inside you'll find the file guava-r07.jar. Select that in this dialog, preferably after moving it to a more desirable location)
Now select Source Attachment -> Edit..., and find the path to the file guava-src-r07.
If you want to, you can repeat this process for the JavaDoc location, pointing it to the javadoc folder from the guava distribution
Press OK.
and some other suggestions are like
use Maven to import the libraries. It makes it simple to upgrade dependencies later and, once you install m2eclipse, Eclipse will pick the Guava libraries up for you. All you need in your Maven pom.xml to "use Guava" is something along the lines of the following in your dependencies section.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
just go through the references also for more details
The very basics for using Guava
How to add Guava to Eclipse project
Adding Google Guava to Android project - significantly slows down the build
If you are using eclipse, just copy guava-07.jar into libs folder(create one if you don't have it).
Select the files in windows explorer and drag them to the libs folder in eclipse. This will also add them to the Android Private Libraries.
I know that there are different solutions with different libraries posted. But, could anyone help me with this one?
I've busting my head for the past couple of days, and I really don't know what to do. I already tried importing the modules in all the suggested ways from different posts. (Project Structure --> Dependencies --> Add dependencies), etc. My project does not show any errors, but when I run it, it throws me a compilation error that complains about some classes missing. The library only depends on the ViewPagerIndicator's library which I also imported.
here is a picture. Thanks!!!
NOTE:I also have tried it with Eclipse, but the problem is different there. The app crashes when I run it. When I uncheck isLibrary from Properties -> Android and erase those libraries, the app works.
Inspired by this answer, these are the steps I did:
Put the jar file (in my case, 'xxx.jar') into the libs folder of your project
Right click it and select Add as library
Type this in the dependencies part of build.gradle file: compile files('libs/xxx.jar')
Do a clean build. It can be done inside the android studio, but I also ran the gradlew.bat included inside the project folder
Now, the project should be built and run just fine.
You are referencing the library wrong. You need to add the dependency in the build.gradle file. I recommend you to read the documentation first. It's a long read, but totally worth it.
I noticed that a user uploaded the library as .aar file in his maven repo. You might want to use the library from his repo. The setup is very easy (you only need to include the dependency of the better picker library).