Error message in Eclipse - java

Can any one tell me what shall I do when Eclipse shows this message:
[2012-02-28 10:57:34 - LMP] Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties.
Actually it was shown when I took a project from anther laptop then I added it to my workspace then I imported it to my eclipse.

Looks like you're using java 1.7 when 1.6 or 1.5 required.

Project > Properties > Java Compiler
Set compiler compliance level to 1.5 or 1.6.

You are using Java 7 on your project, but the VM on Android only supports Java 5~6.
Just have to configure eclipse to use Java 6 compliance level (:

Related

Eclipse Java assistance doesn't comply with compiler level setting

The compiler level used to autocomplete my Java code in Eclipse Neon is 1.8 (proof is it suggests me to use ResourceBundle::getBaseBundleName() for example). I do use a 1.8 JDK but the workspace Java compiler compliance level is 1.7 and project specific settings aren't enabled. How come and how do I change that?

How do I use a Java project that requires a 1.7 compliance level on an Android project build path?

I'm using Eclipse. If I change the compliance level of the main (Android) project from 1.6 to 1.7, I get an error:
Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties.
If I change the compliance level of the "library" (Java) project from 1.7 to 1.6, a lot of the code in it becomes invalid.
Is going through the code of the Java project and fixing every error my single option here?
Google just released Eclipse ADT 22.6 which adds support for Java 7 language features, http://developer.android.com/tools/sdk/eclipse-adt.html. Once you upgrade to to the latest version of the plugin the Compiler compliance level will include the 1.7 option.
Try to clean your project, and fix android properties.
Link here and here
I guess you can find your answer here: Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties
If that doesn't help, I'd suggest to update all android's sdk plugins. I've had similar issue, after updating android's sdk, but I've missed to update android build tools and that caused lot of errors - could be the same with you.
You can use jar builded with Java7 but only in case if it is not using any special features of java7, otherwise dx wont be able to convert jvm byte code to dalvic format.
But there is a one problem: default build process of android sdk (from eclipse e.g.) fails if it finds classes with wrong version (compiled with java7, dx generates warning and fails). You should pass some argument to dx to drop such warnings. Android studio's and Idea's build process doesnt care about this warnings and dx tries co convert java byte code to dalvic despite class version.
Use IntelliJ IDEA instead of Eclipse. In IDEA you can set the Product language level (in Project Structure → Project) separately from the Android SDK's. As long as your code only uses 1.7 features that don't affect the bytecode, it'll work (but the compiler will give you warnings). This way, you can use diamonds, switch on strings, and other syntactic sugar, but you might be out of luck with multi-catch. In fact, you can even use experimental 1.8 features like annotations in strange places, but I haven't tested lambdas yet (since IDEA abbreviates the code anyway). See the intellij-idea tag for more info.
Since Android Studio is a special build of IntelliJ IDEA, it might have the same feature, but I haven't tried in that.
If your library really needs java 7, there is nothing you can do.
Otherwise, go to your library project settings, go to the Java Compiler settings, and select 1.6 .class files compatibility.
If there are errors in your source files, it means your library uses java 7 functions that cannot be compiled in java 6 bytecode. You're screwed.
Otherwise, you can now export a .jar file that you can use in your android project.

androidstudio set java version 1.7

I'm trying to use java version 1.7 with android studio but unfortunately it is not working properly...
If set the version in File->Other settings -> Default project structure to
Project SDK:
java version 1.7.0_06
Project language level:
7.0 Diamonds, ARM, multi-catch
But when I use a switch-statement with a string I get an error which should be possible in java 1.7, so do I need to set any other settings?
No... there is no settings to change. Android SDK don't support full java 7 syntax, so you can't use it.
Note that java.nio.* (new in java 7 API) is supported by latest android version.
You can change it in new Android studio version(0.8.X)
FIle-> Other Settings -> Default Settings -> Compiler (Expand it by clicking left arrow) -> Java Compiler -> You can change the Project bytecode version here
You can change jdk version from File > Other settings > Default Project structure. Then JDK location:

Unable to import package

Hi I am working on an android project that requires File searching.
Now theres one problem that has arised -> I cannot import the package java.nio.file.*;
whatsoever even when I have installed jdk 7. Am using eclipse for android.
Plz help
Earlier I have changed Window>preferences>java>compile>1.7
The project compiles.
But when I changed Project>properties>java compiler>1.7
Then it gives me the following error
"Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties."
Android does not currently support Java 7.
The system requirements for the Android SDK currently specify Java 6.
The current android specifications require your project to be compiled under java 5 or java 6. Like Jason C has said, java 7 is not currently supported.
Unfortunately there isn't much way to bypass this restriction (if you intend to publish your application) so your stuck with rewriting any java 7 code (empty <> operation, try-with-resources, etc) into java 6.
Android Systems only support java versions upto Java 6 and hence the builder is complaining for it. In builder you can create different kind of projects(non-android also), hence it allows to set the java compiler preferences to version 1.7 in windows menu. But if you try to set the java compiler version to 1.7 for an android project, it will not let you.
Android SDK is not x64. So it will not support java7. It will check for any compatible version like java5.java6. So choose java6. That's why you've got this problem. Try Fix Project Properties, if still getting error change version 1.7 to 1.6 from project > properties > java compiler > 1.6!

Deprecate in Java 1.6

In Java 1.5, to deprecate a method you would:
#Deprecated int foo(int bar) {
}
Compiling this in Java 1.6 results in the following:
Syntax error, annotations are only
available if source level is 1.5
Any ideas?
You have to tell the compiler to use 1.6:
javac -source 1.6
Or equivalent for your IDE/build system (as others have suggested).
First, its #Deprecated, and second - double-check if you are really compiling with Java 1.6. What are you using? javac? Eclipse?
If using javac, make sure your JAVA_HOME is set to point to JDK 6, not JDK 1.4.2
If using Eclipse (or any IDE), right click the project > properties > and search for compiler level.
Syntax error, annotations are only available if source level is 1.5
This is a typical IDE error message. You've configured the workspace or the project to use compliance level 1.4 or older. Assuming that it's Eclipse (it's at least recognizeable as an Eclipse error), then you need to go to Java > Compiler in workspace preferences and set the Compiler compliance level to 1.5 or newer. You need to check this in the Java Compiler entry in Project's properties as well.
If you are using Eclipse IDE then
1- Select your project in Project Explorer
2- Go to Project -> Properties -> Java Compiler
3- Check the option for 'Enable project specific settings'
4- Set the 'Compiler compliance level' to '1.6'
NOTE: If already set to 1.6 then change it to 1.5.
5- Press the 'Apply' button.
There are issues with the IDE and at times it just doesn't pick up the default selected compiler compliance level. Therefore you have to toggle it and press the apply button for the changes to take effect.
Having read the responses to date, I can see that there is some confusion as to what is happening where Eclipse is involved.
I had the same syntax error, checked workspace Java compliance (Window > Preferences > Java > Compiler) and was surprised to see a complier compliance level of 1.6. However, I noticed the link Configure Project Specific Settings at the top of this preference page. The link takes you to the project's own settings.
You can navigate there from the main menu, too. In this case Project > Properties > Java Compiler. There is a check box labelled Enable Project Settings and in my case this was checked and the setting was 1.4, though I do not remember setting it explicitly. Anyway, you can either let the compliance setting to default to that of the workbench or change the project setting to 1.5 or higher.
This should fix the syntax error.
I suspect you've got your source level set to lower than 1.5. It should be fine in Java 6 in general.
How are you compiling? If it's with Eclipse, what do your project/workspace settings say under Compiler / JDK Compliance Level?
If you're using javac, run
javac -version
to check what version you're really using.
Are you sure you are compiling with Java 1.6 not 1.4 (or older)?
What compiler are you using?
#Deprecated not #Deprecate
If you are using Eclipse, make sure the settings for the Java Compiler are set to 1.6 compliance.
This can occur even if java 1.6 is used in eclipse. Click the project and then right click it. Go to properties and in Java compiler section first check enable project specific then manually select 1.6 version even if it is already there by default. This fixed my problem.

Categories