Dependent projects and obfuscation - java

I'm working on Android code that exists partly in a library project and partly in an app project; the app depends on the library. But the library is obfuscated, so instead of
import com.mycompany.mylibrary.MyClass
I have
import myobfuscatedlib.MyClass
This works fine in production, but I am trying to debug, and I would like to step into the library's methods; I would also like to be able to edit the library classes, then run the app and see my changes. At present the jar that the library file creates is in the app's build path; if I replace the jar with a project reference, all my imports are invalidated. How can I configure my projects to debug the unobfuscated code while obfuscating for the production build?

Related

Gradle withSourcesJar as library not working

I have a current Gradle, Java 11, project that I intent to use as a library with a set of general purpose functions for another apps.
I'm using the Gradle function:
java{
withSourcesJar()
}
To build a .jar with the source and JavaDoc included. However when I import that .jar into another app (via Gradle implementation) all the non java SDK dependencies in the .jar library fails with a message of the style:
Package 'x' is declared in module 'y', but module 'z' does not read it
Even though that all the required dependencies are already implemented (via Gradle as well) in the host app.
The part that puzzle me more, is that if I build the library jar, as a simple plain .jar(meaning source code but no Javadoc) the library works smoothly when implemented in other apps, it only fails when I try to build it as a withSourcesJar().
So any help that could point me on what I doing wring in the withSourcesJar() or what extra configuration should I add, would be appreciated.
Thanks.

Importing vanilla Java project to use as a library in Android

I've written a piece of vanilla Java code to do a specific task. It contains a bunch of packages and resource files.
I want to import the vanilla Java project to Android to use some of its utilities.
I've tried to build my project to jar file, add it to the libs/ folder and import it. I've also tried to import it directly to the project dependencies. However, none of the above worked. The jar file showed up in the "External Library" part, but I cannot import it from a class inside as it gave me compilation error.
HERE you have plenty of ways how to attach jar to Android project
are you shure that your jar (assuming properly built) will work on Android? not all components and classes of "vanilla" Java are available on Googles OS... check out THIS topic for more info

How to setup stand alone Junit and Mockito without maven

I am working with a very old codebase where no build/library management tool such as maven or ant is used. All library is copied in the local lib directory. I found the stand-alone Junit. That I can import the library in my project. I downloaded and put it in the lib and also configure the build path in the eclipse. I can't import Mokito library in my unit test code. I don't know how do I setup mokito as a standalone library in my project. As shown in the picture below. Please let me know how can I setup this:-
Maybe an easier way to gather all depencies is to configure a maven project somewhere else (using eclipse), then export it as runnable jar. Check the option to export all dependencies into a folder.
You will have to change the scopes, because some scopes are ignored (like test).
Then copy the folder to your old project and import all of the jars into the classpath. You still need to check for conflicts manually.
Or you just mavenize the old codebase instead ;)

How do I add a Github library to my Android Project as a JAR in Eclipse?

I'm trying to add https://github.com/astuetz/PagerSlidingTabStrip to my project. Looking at it, I notice that it has files in res and depends on its own R.java file. When I make it a JAR I continue to get errors because the dependencies aren't all there. I'm not sure how to get this to work.
I keep getting errors like
import android.support cannot be resolved and everything else too. I tried referencing different answers on StackOverflow but none of them yielded a working solution.
The resources won't be packaged into the JAR file. Google is working on a new packaging scheme called AAR which is supported by Android Studio.
In order to use this third-party library in your own project, you should clone it to a local repo. Then you can import it directly into your Eclipse workspace and then add the Eclipse project to the classpath of your app's project.
Download the whole source code from https://github.com/astuetz/PagerSlidingTabStrip by git tool.
On your Eclipse IDE, import the library as exsisting source code at Android option.
Add the library your add before into your project.

Prevent JAR from being imported into Eclipse Java project

I have a Java project which is heavily used by all sorts of other Java and Android projects. The project contains some JAR libraries which shall be used by all projects, except for the Android one (in fact the Android project is a Android library project to be precise).
I marked the JARs as "export" in the Eclipse build path preferences of the Java project. However, the Android project shouldn't import these libraries (as they are Java libraries which make use of some classes which are not available on Android), but it shall import the rest of the code (which doesn't really use the libraries, but they are stored in there for convenience reasons and to ensure, that all other projects use the same library.
How can I prevent the JARs from being exported to the Android projects?
You can prevent all jars from being exported so that only the common project is a dependency for each project that needs it.
Then you can change the build path of each project to only include its necessary jars through the add jar.. dialog in build properties.
That's the easiest way.
A more extreme way would be to move to maven and then eclipse will only include the jars you specify in the pom - though that's a load of extra work for not much gain.
Alternatively, you could split the android specific code into a android-common separate project and then make your common project depend on it and export it - then your android project could rely on this android-common project instead of the existing common project.

Categories