I learn development for android, I would like to see how certain application is built, I also would like to adjust its UI controls positions for sole use.
So, I decompiled the application and try to build it with Eclipse bundle. I got an apk file built, but when I start it it produces the exception "java.lang.RuntimeException: Unable to get provider iching.android.contentprovider.DivinationProvider"
But I see the file src/iching/android/contentprovider/DivinationProvider.java which contains missing class definition:
package iching.android.contentprovider;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import iching.android.persistence.IChingSQLiteDBHelper;
public class DivinationProvider extends ContentProvider
{
How can I get compiled apk which can't find a class, used in it?
Why does not it find the class declared in properly placed source file?
UPDATE:
I found java compiler was disabled, so bin/classes remain empty on build finish
UPDATE2:
Yep there was a lot of errors when I enabled javac.
I give it a shot to answer your questions but i have to admit its half guessing since i dont see actual results of your decompiling/ running attempts:
0.) Make sure the app (.apk) you have runs as it is (e.g. "it works" as delivered from its producer)
1.) Since decompiling (even in Java) is not trivial as soon as there is complex (or "obfuscated") input data it is very likely the decompiled source will not compile.
=> In 99% of the cases decompiling is used to understand how something work using static code analysis rather than "just run it".
So "the lack of skills" of decompilers CAN lead to what you call "compiled apk which can't find a class, used in it". Mostly however because Class-dependencys were not decompiled correctly.
2.) Because it is not there. It is that simple. Assumed the decompiling worked properly (it looks as it would since you dont have any compile time issues) you are just missing the dependency iching.android.contentprovider. Recheck all of the 3th party librarys are getting attached to your final build-output (i assume a .apk file) correctly. Unfortunately i dont know how you are building your project.
Related
I have same jar lib for android where I need change class. I opened .jar find and decompile class, do same changes. I need add updated file to jar. As I understand I need compile .java to .class, and then repack jar.
I try convert to classes with javac.exe MyClass.java and I get a lot of errors like
import android.annotation.SuppressLint;
.java:8: error: package android.content does not exist
import android.content.Context;
.java:9: error: package android.graphics does not exist
import android.graphics.Color;
in total 149 errors
Do you have any ideas?
These error messages are the java compiler telling you that there's some android dependencies that he can't figure out how or where to find.
I don't think it's possible to achieve this, because it seems your class relies on Android framework resources.
Take a look at:
compile android app with javac
Did you consider inheritance ? I mean, the desired different behaviour for android maybe can be achieved by inheriting the class then overriding the specific method with new behaviour, I'm just guessing, since I don't have enough info about your problem.
I'm writing a Java class that will be used to send PDUs across a network- to do this, I am following the tutorial at: Tutorial
In the example, the line:
double lla[] = CoordinateConversions.xyzToLatLonDegrees(c);
appears towards the end of the class, and I see that CoordinateConversions has been imported with the line:
import edu.nps.moves.disutil.CoordinateConversions;
I have tried using the xyzToLatLonDegrees(); method in the class that I am writing- calling it in the same way as is done in the example. However, for some reason, I get a compile error that says:
CoordinateConversions cannot be resolved
on the line where I'm trying to use it, and
The import edu.nps.moves.disutil.CoordinateConversions cannot be resolved
on the line where I am importing it.
Does anyone know why this is, and how I can fix the import, so that I can use the xyzToLatLonDegrees() method?
You need to have the CoordinateConversions class on your classpath. Either by obtaining the source and dropping it into your project (possibly adjusting package names, and only if the license allows), or by finding a JAR containing that class and adding it to your build path in your IDE.
You probably need to download the Java files from here.
I'm trying to compile a small test program I have written for a raspberry pi.
The program makes use of the Pi4J library to control the piface add-on board.
What I have done so far is based on the following tutorial: http://www.savagehomeautomation.com/piface
While I can get the above example program to compile within my IDE after setting up the class paths I get compile errors with the one I have made and as far as I can tell the imports are set up in the same way.
It says that each of the following packages does not exist:
import java.io.IOException;
import com.pi4j.component.switches.SwitchListener;
import com.pi4j.component.switches.SwitchState;
import com.pi4j.component.switches.SwitchStateChangeEvent;
import com.pi4j.device.piface.PiFace;
import com.pi4j.device.piface.PiFaceLed;
import com.pi4j.device.piface.PiFaceRelay;
import com.pi4j.device.piface.PiFaceSwitch;
import com.pi4j.device.piface.impl.PiFaceDevice;
import com.pi4j.wiringpi.Spi;
I'm assuming that my problem is relatively simple but I don't really understand how import statements work and it's quite vague topic to search about. I have included some file paths if that helps.
This is where my project resides:
/home/pi/JBerries/relay
and this is where the pi4j library is:
/opt/pi4j
I hope the following image provides some of the information requested, note that the class paths are already set up:
You need to set the CLASSPATH environment variable to /opt/pi4j or the jar file therein. WIthout this the compiler is unable to know where your libary is located and will give you the errors you describe.
If you're using a project in JBerries you need to configure the classpath for the project - the screenshot shows the classpath for single-file compilations only. To edit the project config right-click the root node in the project window and select properties.
This is taken from the bytecode of Minecraft. Most of the jar's classes are found in the default package, however there is another package, "net.minecraft.client", which has the main class (Minecraft.class) that runs the game loop, sets up OpenGL, etc. I don't have the source, but if I open up Minecraft.class in JD-Gui, it has the following import setup:
package net.minecraft.client;
import aaa;
import aai;
import ajq;
import ajv;
import akf;
import aki;
import aqx;
import aqz;
import ara;
import arb;
... (many more classes from the default package)
public abstract class Minecraft implements Runnable, mc {
...
}
How does this work? Let's say I have a folder with a similar setup (default classes that need to be accessed by other packages) and want to compile it with a batch file. What method of compiling could replicate this result?
This is taken from the source of Minecraft.
I don't think so. (EDIT: The question was edited to make this "bytecode" - which doesn't make much sense, as bytecode isn't Java source code. Anyway...)
How does this work?
It doesn't, fundamentally. The code you're looking at in JD-Gui isn't the original source code - it's code which represents the bytecode as accurately as JD-Gui is able to manage.
I strongly suspect the original source code does use packages, but then uses an obfuscator of some kind to rename the classes and put them in the default package. I strongly suspect this isn't the only kind of change which leaves valid bytecode which couldn't actually be directly compiled from valid source code. (For example, I strongly suspect there are method names which are valid in bytecode but not in source code.)
Let's say I have a folder with a similar setup (default classes that need to be accessed by other packages) and want to compile it with a batch file. What method of compiling could replicate this result?
You wouldn't. You'd have source code set up using packages (as all sane, non-trivial Java code does), compile it and then post-process the bytecode.
Okay, first the project I am working on has two packages, first is murach.business which contains invoiceCalculations.java Second is murach.forms which contain InvoiceForm.java(JFrame) and SwingValidator.java
So, I am supposed to add Add import statements for the murach.business.InvoiceCalculations and java.text.NumberFormat classes in Invoiceformjava that i created from the scratch.
But, I am getting errors when i code that. netbeans says unused code for the below code:
have i written the code incorrectly? whats wrong? Please push in right direction.
import murach.business.InvoiceCalculations;
import java.text.NumberFormat;
"Unused code" doesn't mean that you have a syntax error. It just means that the import is not necessary, because the current code of the class doesn't use the imported class yet. If you add code inside the class that uses the imported class, the warning will disappear.
Note that, with current IDEs, you usually don't bother adding import statements manually. You use the class without importing it, and use a keyboard shortcut (or autocompletion) to add the necessary imports (and remove the unused ones) automatically. In Netbeans, the command is "Fix Imports (Ctrl-Shift-I)"
These are not errors but warnings that Netbeans gives you. The code should still compile fine