Order and Export not working - android

I have a simple java project and I reference it from an Android project. In MainActivity of android project I create an instance of an class which is defined in simple java project. This used to work until I physically change paths of project folders. To make sure that android project has the right project reference I deleted old project folders and re-added project reference. My code compiles. But though my java project is checked at Order and Export tab of android project, when I try running the app on a device, I still get NoClassDefinition exception. This exception is thrown any time android project tries to access any class defined in java project. In other words
Object o = AnyClassInJavaProject.class;
causes NoClassDefinition exception.
To test, I added another java project, defined class 'a.B', referenced this project from android project, checked new project from Order and Export tab, added below line to MainActivity code and again NoClassDefinition exception.
new a.B();
What am I doing wrong?

It was because 'Compiler compliance level' of java project. It was 1.7 and making it 1.6 solved the problem. I used to get Unsupported Minor Major exception for this case but for android applications it seems like unsupported versions are not included apk and causes NoClassDefinition exception.

Related

Need help setting up RoboSpock

I want to use RoboSpock for Testing my android apps, but I am stuck setting up my project. I created an example project which I have added to github.
https://github.com/DerSchimi/RoboSpockExample
This project contains a folder called AppLibrary which is an android-library. The App itself is inside the folder App.
All RoboSpock Tests should go inside the folder AppTests. I have configured everything, but when I try to run my tests I get this error message:
WARNING: no system properties value for ro.build.date.utc
groovy.lang.MissingPropertyException: No such property: AppActivity for class: de.derschimi.app.MainActivitySpecification
at de.derschimi.app.MainActivitySpecification.Should say hello world(MainActivitySpecification.groovy:15)
This is the line of code:
def mainActivity = Robolectric.buildActivity(AppActivity.class).create().get()
Is there anybody out there who is using RoboSpock? Thanks a lot for your help!
The plugin I consider as deprecated. At this moment I'm creating just samples how to enforce gradle java plugin understand the android one. I suggest to browse this project.
https://github.com/pjakubczyk/robospock-sample/tree/master/simple

Android: NoClassDefFound error

My setup is as follows:
I have an android project A, and a java project B. Project A uses some files from Project B.
My development environment is eclipse, and I have included Project B in the build path,
as well as marked it for 'Order and export'.
The project builds fine, but at runtime I get a
java.lang.NoClassDefFound error, when I am trying to reference a class from Project B.
How can I resolve this?
I am using eclipse Juno, and ADT 20.0.3.
Thanks.
As you talk about having updated your Eclipse and your ADT, maybe you also changed your environment to Java 7?
If that is the case, the answer would be:
Switch back to Java 1.6.x, as Java 7 is not (yet?) supported by Android.
You need to change the "compiler compliance level" under:
Window - Preferences -- Java - Compiler - Compiler compliance level
Hope that works, at least it did for me:
NoClassDefFoundError when referencing from an Android-Project to a standard Java-Project
You can also try to export the java classes you need in a jar, and include that jar in your Android project.
I had the same problem when I was trying to reference another class withing the same project itself.In my case, the problem was solved when I rechecked the android dependencies. I added two jar files for a single required file. There was a need of android-support-v4.jar file in my project. I added the library twice by mistake. The error was resolved when I deleted one of them.
For me this was happening when using the AIDE development environment. It has happened a couple of times over the past year.
When the Java diamond operator is used to specify a function's generic type the program will compile, but the Dalvic engine crashes with the NoClassDefFound exception.
To fix this I had to explicitly define the generic type.
By the way, this crash can happen in a completely different place to where the problem actually is. For example, we have classes A and B. The bad code is at A.myMethod(). The crash will happen when class B attempts to access any part of class A, even something unrelated such as A.myOther() method.
This is because of how Java/Dalvic loads classes at runtime only when first accessed.

Unable to load Facebook SDK to Eclipse. Build Path Error

So I have not been able to even start coding for the app I want to build, I am having a really hard time getting the SDK set up for me to code based on it.
Here is what I did:
Downloaded Eclipse
Downloaded the JDK, Android SDK, and ADT on Eclipse.
Created a directory named "Facebook", where I cloned: https: //github.com/facebook/facebook-android-sdk .git (Separated to avoid the spam mechanisim :P)
Created a new project from existing source; please note that on the tutorials it reads "Create project from existing source" as an option within the "New Android Project" workflow, but my Eclipse only has "Android Project From Existing Code" (see: http://db.tt/gOmutx08 and that is what I used) as a separate workflow. Also, there is no "New Android Project" here, only a new "Android Application Project" and this does not prompt me to select an existing project as source (see: http://db.tt/usuzcTxS ). Not sure if this is where the problem is coming from.
Created a new project, and added the SDK project we created previously as a reference library.
The problem must definitely be on step number 4 as I get the following errors on my Eclipse Problems logger:
a) Description Resource Path Location Type
The container 'Android Dependencies' references non existing library 'F:\Users\Desktop_1\Android\Facebook SDK\facebook-android-sdk\facebook\bin\facebook.jar' Test-Facebook Build path Build Path Problem
b) Description Resource Path Location Type
The method onClick(View) of type new View.OnClickListener(){} must override a superclass method FbDialog.java /facebook/src/com/facebook/android line 101 Java Problem
c) Description Resource Path Location Type
The method onServiceConnected(ComponentName, IBinder) of type Facebook.TokenRefreshServiceConnection must override a superclass method Facebook.java /facebook/src/com/facebook/android line 575 Java Problem
d) Description Resource Path Location Type
The method onServiceDisconnected(ComponentName) of type Facebook.TokenRefreshServiceConnection must override a superclass method Facebook.java /facebook/src/com/facebook/android line 581 Java Problem
e) Description Resource Path Location Type
The project cannot be built until build path errors are resolved Test-Facebook Unknown Java Problem
Where the main problems are a and e, as the project cannot be built if there is an issue with the build path. Problems b through d can easily be fixed by removing the "#override" annotation from all three lines; however, I am not sure this is the actual fix because the SDK should have no issues in the first place, and removing the annotation may not make it work in the end.
Any ideas as to what I could try? I have already deleted the whole SDK download, and recloned the repository several times, even on different folders. Not sure anymore, and I am not sure why the screenshot from the tutorial looks way different than my eclipse. My guess is that the tutorial is slightly outdated as it still uses Froyo as a target :P
Any help is appreciated.
I had faced most issues you faced. I had it resolved.
Eclipse for some reason chose to keep facebook project is Java 1.5 eventhough my eclipse preferences had the setting to use Java compiler 1.6.
So, go to Project Properties in facebook project and select the java compiler to be 1.6. This solved my problem. Hope it solves yours too.
I've repeated Your steps and found out the following:
Seems Yours facebook project is not library one. Please, ensure that under facebook project Android properties 'Is Library' is checked (this should remove a and e errors);
Create project from existing source == Android Project From Existing Code
I think you have downloaded newer version of Android SDK - API Level 16 - Jelly Bean..
Before API level 16 , we had an option for Create project fron existing source , now it has been changed.
So if you wanna use Project from particular location you can use Android Project From Existing Code..
Also after creating Project make facebook source as library project...

Regarding NoClassDefFoundError

I have used the isEmpty and isBlank methods of apache's StringUtils Class. These methods worked in a fine manner, after couple of weeks suddenly i got the error
java.lang.NoClassDefFoundError: org.apache.commons.lang3.StringUtils
I was confused why this error happened suddenly.It would be fine if anyone help me to understand this suddenly happened.
People Saying that apache might have changed the definitionin their JAR file, is it a right one,i really confused why this suddenly happened , i removed the old jar from my build path and downloaded the same version of New Jar and added it to Build path, then this issue is resloved.
It is happening in the Market Code , there's no interaction with ADT and market code
so really confused on this issue?
This occurred to me too - after updating the Android SDK Tools. In current version (19), what you need to do is:
make libs/ folder in project's root directory, and put all jars there (folder's name is fixed "libs")
after this, go to project properties --> Java Build Path --> Libraries, and remove all custom jars you previously added
NoClassDefFoundError says NoClassDefFoundError is Thrown if the JVM or a ClassLoader instance tries to load in the definition of a class and no definition of the class could be found.
Maybe startup script is overriding Classpath environment variable.

Eclipse ADT cannot set conditional breakpoint on SDK sources: missing java Project context

I am trying to debug a simple Android app with Eclipse 3.7.1. I attachted the Android SDK sources so I can step through the code of the SDK also. I can set unconditional breakpoints on code of the SDK but not conditional breakpoints. I get the following error message if I try:
Conditional Breakpoint Error
Conditional breakpoint has compilation error(s).
Reason:
Unable to compile conditional breakpoint - missing java Project context
Conditional breakpoints on by own sources work, however.
The only relevant search result on the topic I found suggests to convert the project containing the third party jar into a Java project. But I do not know how to do this for the Android SDK, i.e. how to add it as an Eclipse project at all. (Would that be even sensible?)
To fix this error, create a new Java project for the Android library your project uses. Link the sources of the Android library delivered by the SDK to that project. Exclude everything (*), otherwise warning and error messages will flood your log! Attach the source code from that new project to the «android.jar» your project uses. That's it.
I wrote a more step-by-step solution here.

Categories

Resources