How to add custom library in android studio java? - java

I have downloaded a source of library but I really need to make it custom and change it in my own way, so I should import it as a module to my project manually.

Follow these steps:
1. Create a folder.
2. Drag or copy your library folder in created library in android studio.
3. Add the module to the settings.gradle like this:
include ':LibraryFolder:LibFolder'.
4. So sync it and clean project.
5. Go to project structure in Android Studio.
6. Add library.
7. Clean and run.
Be successful.

Related

How to add external dependencies in VS Code?

I have a Java project, which is an Intellij IDEA project, not a maven or Gradle project,
I want to work with the project in Visual Studio Code now, but I have a problem, I have an external dependency for handling CSV files called Jsefa(Java Simple Exchange Format API).
How can I add this dependency to my Visual Studio Code Project so that I can build the project in VS Code easily that uses this library??
Can I do this with some modifications in the settings.json file? or is there another way??

External library dependency under Android Studio

I have my Android Studio project structured as follow:
/mysdk
-manifests
-java
-com.xxx.sdk
-ext-libs
-com.yyy.lib (not .jar but .java files instead)
-res
/app
-manifests
-java
-res
I can include com.yyy.lib.* inisde com.xxx.sdk and reference all the methods without any symbol resolution problem in Eclipse project.
But after I transfer my IDE from Eclipse to Android Studio and it tells me it cannot resolve the symbols/methods from com.yyy.lib inside com.xx.sdk (ex: com.xxx.sdk.Activty.java)
How can I fix this dependency problem in Android studio?
If you have no strong preference for the location of com.yyy.lib, just moving it into the parent (is it src/main/java? based on gradle convention) it will probably get picked up.
It appears the IDE is treating src/main/java (or whatever) as a source folder and your package paths aren't matching up with your directory structure
ext-libs.com.yyy.lib instead of com.yyy.lib
That's because Android Studio uses Gradle as its dependency manager, whereas Eclipse uses either Maven or Ant.
You can read more about managing dependencies with Gradle, here.
This answer explains how to add a dependency/library to Gradle in Android Studio.
In your project file browser:
Go to libs folder. and add your library if not present
and then in gradle: add compile files('libs/your_library') in dependencies and then Sync Gradle

How Do I Import a Non-Android Eclipse Maven Project into Android Studio?

I am starting at a disadvantage as I know neither Eclipse, Gradle or Android Studio. As such, I may not be using the correct terminology for everything, but I'll give it a shot. My ultimate goal is to get a working Eclipse-based Android app imported into Android Studio and hand it back to the Android developer. This question is about a problem I encountered on the way.
I have successfully imported the main Android project into AS. Now I'm trying to pull in another project it depends upon as a module. The dependency is a Maven project. It has a pom.xml, a .project and a .classpath. It's not an Android project, so there's no AndroidManifest.xml. It has a src but no res folder. I want this project to be a module rather than an external dependency as the developer will modify the source code on occasion.
The problem is that AS refuses to accept the project as an importable module. The Add Module dialog, when pointed to the project's root directory, continues to warn that I haven't yet selected a valid Android Eclipse or Gradle project. The Next button stays grayed-out. I agree that this is neither an Android-specific nor a Gradle project, but I have read here that IntelliJ IDEA will import such projects. It appears that AS will not.
There are several other non-Android Eclipse projects that also won't import as modules in the same way. These include ordinary Maven and ant-based libraries.
How do I accomplish this? The GUI seems out to thwart me. If I get down to the Gradle XML level, can I do it and will the modules show up normally in the GUI? Do I have to go back to Eclipse and convert these to Gradle projects first?
Thanks in advance.

JAR libraries not being detected

I created a fresh project in Android Studio which uses external library (JAR). I put this in modules's build.gradle:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/mylib.jar')
}
But, when using Android Studio editor, it says there are some errors in my code and marks imports and variables (which use this library). It doesn't build properly saying that it cannot find one or another class. However, when I go to project's directory in terminal and execute gradlew manually, it builds APK and it (the APK) install and works just fine.
What am I missing? Is there any another setting in my project which is used for library detection?
Android Studio currently does not automatically sync your Gradle build files with your Android Studio (.iml) files. However, version 0.1.3 added a new sync button to the toolbar that will do this manually.
It's mentioned in the second bullet point of this blog post.
There were a lot of fixes in the Gradle project import and build
areas. There is now a "sync" button in the toolbar which will reimport
the Gradle project state into your Android Studio project. Use this
after editing your Gradle files, for example to add a library. In the
future we will more automatically handle state syncing, but for now
this is the simplest way to keep the IDE up to date with project
structure changes made to the Gradle files.

Include java project into android build

I've got such a problem
I have to include external java project into my android build.
The project structure is:
Alpha - project with shared classes and libs.
Beta - android project that uses files from alpha
Gamma - desktop java project that uses files from alpha.
Everything works fine on Eclipse, but I need it to work on Jenkins.
I'm using Google Android SDK (android update project command) to create a build.xml, and then I'm using google targets to do what I need (build, emma, clean and so on)
The problem is that this build.xml does not include files and libs from alpha project, so it basically failes at first line of beta build task.
My question is:
How to properly add alpha project as a dependency for a googles generated build.xml file?
Should I compress alpha to .jar and then add it somehow to beta (how?)
Should I just link it somehow?
Thanks for all help.
[I'm new to ant scripting so please write in plain engish:P]
Yep, this sucks! When using Jenkins and sharing one lib-project on different projects, you'll have to compile your lib-project (alpha), as you already mentioned, copy the jar to the respective directory of both projects, and link them in the Build Path Settings.
This is quite a lot of ANT-Stuff, you'll have to look into, but don't get discouraged, it ain't rocket science :)
Basically you have to do this:
Create an Ant-script that compiles your shared project, and copies it to some lib-directory in both projects
Link the Jar in the Build Path of your desktop and android project
For Jenkins: Customize android's build.xml (e. g. add a new target), so that it executes the lib project's build.xml (compile the project and copy the jar).
Run it on Jenkins
If you don't want to compile the shared project (manually) each time before you run your android or desktop project in eclipse, you should add the shared lib's build.xml with the respective targets to the projects' builder settings (in Eclipse -> right click on Project -> Properties -> Builders -> add the new builder between the Java and the Android package builder).
Sorry dude, I don't know any other way. Maybe there is another solution out there, I haven't used Jenkins for a year.

Categories

Resources