How to add local jar library to visual studio code? - java

I've downloaded some jar files (e.g. gson-2.8.5.jar) and want to add them to visual studio code locally without any extra downloads so I can benefit from autocomplete feature of classes and methods, How should I do it?
I've searched a while in google and could not find anything useful, so even links to other answers is appreciated.

As suggested by LeoZhu-MSFT which references this in comments all I had to do was open only the folder containing stand-alone Java files and if necessary put any jar dependency in a lib subdirectory (I was previously opening all directories with code snippets I work on in different languages as playground).

Related

How to convert .dex files to android studio project

I have an apk debug file and a zip file with same contents. There are some .dex files META-INF, AndroidManifest.xml and so on. Is there any way to import it to an android studio project to edit app classes?
Yes, but it's going to be a hassle to do.
The JADx GUI can open an APK and will decompile all classes and resources in a read-only mode. You can then use the "Export to Gradle Project" function to do exactly what it says.
However, it's not exactly reliable. Sometimes it doesn't extract so you need to do it again. When it does finally create a project, you'll notice that the Gradle version is sorely outdated, so you'll need to update it.
Other things to note:
If the project uses libraries, they will be integrated into the project tree in Android Studio. This is because libraries are built into the APK during compilation.
There will be potentially thousands of duplicated resources that you'll have to manually delete.
There will be invalid resource folders
There will be invalid Java code:
JADx can't decompile everything, and will leave empty methods
If there are multiple anonymous classes of the same type used in a class, JADx usually only decompiles one.
As someone who's done this, it's honestly easier to just learn Smali and use APKTool.

Downloading Eclipse Platform Source Code

Before this question is blocked for duplication, I would like to say that it is more specific than Downloading Eclipse's Source Code and Downloading Eclipse Source Code and Eclipse source code download , as well as they do not provide I clear way to download the code.
I need to analyse the eclipse source code through metrics more specifically the platform source code. First of all, I would like to know which are the packages that composes the Eclipse platform. Next, I need to download the platform source code, however I already tried different approach with no success. The ways that I already tried:
1) First, I tried to download the RCP SDK from (archive.eclipse.org/eclipse/downloads/), however, there is only a set of .jar files inside.
2) When I select the package related to platform (git.eclipse.org/c/?ofs=350), and next select the branch (for example, R2_0_1 ), the tree tab shows that it has only one .java file in the src folder (for example: http://git.eclipse.org/c/platform/eclipse.platform.git/tree/platform/org.eclipse.platform/src/org/eclipse/core/launcher?h=R2_0_1).
3) I also tried to get it by cloning the git repository as suggested by eclipse website (http://projects.eclipse.org/projects/eclipse.platform/developer), the same problems happens, there is only one .java file when you select src folder.
4) I tried to identify the packages which compose the eclipse platform by analyzing the Bug repository (http://bugs.eclipse.org/bugs/buglist.cgi?bug_status=all&content=platform&limit=0&list_id=10384608&product=Platform&query_format=specific). However, there are some components listed in the bug repository(such as,
eclipse.platform.common.git, eclipse.platform.git and eclipse.platform.news.git) that are not listed here (git.eclipse.org/c/?ofs=350). This way, I`m not able to identify which components compose the platform.
This way, I would like to know if is there any way to download the Eclipse Platform source code and identify its packages.
Thanks in advance.

Using a Java Method from another Project

Similar questions to this have been asked several times, but none of the answers fits my situation.
I have a Java project which I originally wrote to run on a PC. The classes containing the functional stuff are separate from those containing the GUI and PC specific bits and pieces. Now, I want to reuse those "generic" classes in an Android version.
I've created a new project in Eclipse. I've used the Build Path / Link Source item to point to the folder of my original project. Now links to the the .java files appear within my new project. I still can't invoke a method from the original project in my new one. I believe this option is only to allow the files to appear in the project and that it doesn't actually do anything functional.
Elsewhere, I learned of the ability to add the source in the Source path tab of the Build Path / Configure Build Path option. No joy with that either.
Another responded suggested adding the original project in the Projects tab of this dialog. This didn't help, either.
I've even tried multiple cantations of "import." Not even sure I should need to. No luck.
How can I resolve my "blah cannot be resolved to a type" warning in my Android project, when trying to call the method from my non-Android project, please?
Is there something missing from the raw Java which is required for an Android build?
You need to create a snaphot/util jar of the common project and include the jar in classpath of the dependent projects. This will fix your IDE problem.
During the deployment, make sure to include this new JAR in lib/classpath location of the deployable projects.

Adding external package to Android

I have pretty much no experience with Java so I apologies if I'm not too clear.
I'm trying to create an Android application that uses another package. I only have the source code .java files from the package, which are all part of com.X.Y
I have saved this in a folder called "Database" which I have zipped and added to the build path, so it now appears under "referenced libraries" in Eclipse. However I don't know how to include this, it's not finding import com.X.Y, and I am unsure of what to do next.
I'm a little over my depth in this project, any help would be greatly appreciated
Create a folder structure com/X/Y within your source folder and put your .java file inside of that
Step #1: Move the classes out of "Database" and into the main source tree of your project.
Step #2: There is no step #2.
I strongly recommend that you step away from Android for a while and learn Java separately. There are tons and tons of materials to help you learn Java, including lots of free stuff online. Here is a blog post where I point out a number of topics in Java that Android developers need to learn.
If you want to include those files as an external library I would look at creating a proper jar of the compiled code you want to include instead of just zipping up the source. For you the easiest way would probably be to create a second project in Eclipse, compile it and use the resulting jar.
Once you have the jar, put it in the libs subdir of your Android project. I believe that's enough to get the Android ant target to work...although for Eclipse to be happy I believe you will also need to add it to your Java Build Path.
Or if you are hell bent on just including raw source you may as well just copy/paste the entire package source into your android source directory.

Android shared library which is not JNI based

I am developing a library for Android applications which does not use native code (JNI). I have tried suppling the library as an external jar in my Android projects but this method does not include the library contents in the apk and thus throws class not found errors when run in the emulator or device. I have also tried creating the library as an Android project in itself and this does work, but only for public static properties (not methods). With the library and application both being in separate apk's I can see that the VM notices references to the library and can read some properties, but when an attempt to instantiate a class in the library is executed I get class not found even though I can read the public static properties from it (very frustrating!!).
I realize that Davlik byte code is not the same as Java byte code but I am having trouble even finding good information about how to solve what would seem to be a very simple issue in Android. I am looking into the old PlatformLibrary stuff right now but I am not convinced this will work either since the sample has been removed from the Android site :(
So help me out if you can, if I find the answer before this happens I will share it.
viva la Android!
I have tried suppling the library as
an external jar in my Android projects
but this method does not include the
library contents in the apk and thus
throws class not found errors when run
in the emulator or device.
Put the JAR in your libs/ directory, and it will automatically be included in the APK.
This sample project from one of my books shows using the BeanShell JAR this way. Also, all of the GitHub repos starting with "cwac-" on my GitHub page are projects designed to build JARs to be included in Android projects via the libs/ directory.

Categories