To remove a library reference from the project classpath, follow this procedure:
1.Right-click on the project in the Project Explorer view and select Properties from the drop-down menu.This will open the Propertis dialog.
2.On the Propertis dialog, select the Java Build Path from the list of properties.
3.On the Java Build Path part of the dialog, select the Libraries tab.
4.Find the entry in the list of libraries called Shared Library [], and then select it.
5.Click Remove.
Answer from Mihir on Stack OverflowTo remove a library reference from the project classpath, follow this procedure:
1.Right-click on the project in the Project Explorer view and select Properties from the drop-down menu.This will open the Propertis dialog.
2.On the Propertis dialog, select the Java Build Path from the list of properties.
3.On the Java Build Path part of the dialog, select the Libraries tab.
4.Find the entry in the list of libraries called Shared Library [], and then select it.
5.Click Remove.
Right click on project, goto Build Path -> Configure Build Path, then goto the Libraries Tab, select the Referenced library and click remove.
Go to Window -> Preference -> Java -> Installed JREs -> select the jre -> edit -> click on the jar to remove -> remove on the right menu.
Easier way would be
File->new java project->configure jre(blue text)->(it will show the installed jres and you can remove any which you dont want)
Videos
Maybe You have to go:
right click on your project:
properties > select "Android"
Under "Library", remove the library you want.
It maybe some libraries include other libraries so you couldn't remove it from where you have tried.
Right click on the jar file -> Build Path -> Remove from Build Path
This is what I did finally
I used JBOSS TattleTale (http://www.jboss.org/tattletale) to identify unused jars at compile time (It reported 17 jars as unused).
Then for each of the jar in that list, I did a string search on my project to find if the highest package level of the jar was used anywhere (this is an attempt to see if any class belonging to this jar was loaded using reflection).
This way I was able to successfully eliminate 6 jars from my project.
Since, number of unused jars at compile time was small, this approach was quick.
If there's a better solution to this, I'd love to hear it.
The problem is that even if a jar isn't needed to compile, it could be needed to run. And this "need" could be transitive. EG: A jar you use needs a jar you don't use and only at runtime. As is the nature of runtime errors, they'll only reveal themselves when you try to execute the code. Worst case, that may not occur until you're running in production.
The best solution I know of is exactly what you don't want to do: "removing one or more jars, then compile/run to test if those are required or not".
Can I delete or remove the library... programmatically?
No.
Can I... stop the service in the main activity programmatically?
Possibly. Ask the developers of the library.
I've tried to add the following lines to avoid the error but it fails
Nobody knows what "it fails" means. Contact the developers of the library and ask them how to use it with Android 8.0+ devices.
I discovered a possible solution to solve this problem, we can use PackageManager to enable/disable a Service/Receiver/Activity from third party library.
ComponentName component = new ComponentName(context, MyReceiver.class);
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED , PackageManager.DONT_KILL_APP);
Thanks Varun's answer.
Use a SecurityManager instead of hacking the JDK
I'm going to give you the best answer I can.
Why you really shouldn't be doing what you want to do
When you're writing code, it is commonly agreed to develop that code in a way that is extendable. That is, your code can be plugged into other applications, or it can be changed and added to, very easily. Now with that principle in mind, let's review what happens when you delete the possible functionality of your program. Say you delete the SQL package, and in the future, you want a backend database to provide some persistence in your program. You're screwed.
The idea of Java, in fact I'd go as far as to say the major advantage of Java, is it's commonality, consistency and standardization of patterns. A getter is always a getter. A variable (that isn't a constant) starts with a lower case letter. Classes have a standardized way of being structured. All these things make developing in Java quite intuitive.
The JDK is part of that consistency, and to edit it is to really impact one of the major points of Java. It sounds like you want to implement your program in a different, more compact language.
Finally, you have no idea how the client may want to extend your project in the future. IF you want to have some repeatable business from the client, and generate a good reputation at the same time, you want to design your code with good design practise in mind.
