Android samples - Accelerometer and APIDemos do not build - android

I am new to Android development. I have succesfully installed eclipse with Android Developer Tool plugin and many of the samples work fine.
But Android samples - Accelerometer and APIDemos do not build. I see many build errors notifying to fix the errors in code. I dont think Google has released APIDemo sample with build errors.
Thanks in advance, please advice how to fix these errors, or if any configuration/setting is required.
I have set the Java compiler compliance level to 1.6.
Error information(for acceralometer sample):
The project contains error(s) in application. Please fix them before running
Error details:
The method onAccuracyChanged(Sensor, int) of type AccelerometerPlayActivity.SimulationView must override a superclass method
AccelerometerPlayActivity.java /AccelerometerPlay/src/com/example/android/accelerometerplay line 456
Java Problem
Call requires API level 8 (current min is 5):
android.view.Display#getRotation AccelerometerPlayActivity.java /AccelerometerPlay/src/com/example/android/accelerometerplay
line 389 Android Lint Problem
Regards,
Jai

Look for the line androidminSdkVersion ="5" in your android.manifest file
and change its value from 5 to 8 or anything more than 8
Alternative is
Go to project properties by right clicking on you project,
thereafter look for Android in properties.
You have to select the build target here equivalent to the api for which it the sample project is build for
Refer Image
Say if you are using the sample from folder android-12 then you have to check the same option(ie API Level 12) here in properties

A possible reason can be a slow PC, which does not build in time. Then errors occur due to absence of R.java
In that case (errors are with something like R.id.stuff), build the project and wait.

I found the fix myself!
Earlier I tried with Andriod version 4.0. Now I just tried ApiDemos sample with Android version 4.1.2. It worked fine. I also deployed the apk in my mobile. It just works fine.

Related

How to find cause of error when dexing: MethodHandle.invoke and MethodHandle.invokeExact

I have a project that has started throwing this error when building in Android Studio or Gradle:
com.android.tools.r8.ApiLevelException: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
Now I assume that it's related to use of Java 8 features, perhaps a lambda, but the error message gives no clue as to where the problem lies - it could be my code or it could be a library.
What's the best way to find out where the offending code is? It's a reasonably large app with several modules and quite a few libraries.
In my case i tried to mock something via mockk in an instrumentation test running Api Version 26 or higher, removing the dependency was my only solution as long as following issue is not resolved: https://github.com/mockk/mockk/issues/281
Update: It seems that the issue got resolved and using mockk version 1.10.0 will resolve this issue
One approach would be to set your min api to 26, to avoid the error and build the apk, and then inspect the bytecode of the app (dexdump, baksmali, etc.) to find any usages of the MethodHandle class.
Looking through the error log, it did give a bit more information, specifically nominating one jar file that it failed on:
/Users/.../androidApp/build/intermediates/transforms/desugar/debug/41.jar
On examining that jar file, the classes were all from a library recently added to the project, and the very first class listed was:
META-INF/versions/9/org/h2/util/Bits.class
This turns out to be a Java 9 customised class. Deleting it from the jar file (using zip -d) solved the problem.
Just change the mockk version to 1.10.0, this will resolve the
I have same case when used too high version of Mockito library.
The solution was downgrading from 3.8.0 to 3.4.6. and everything started to work properly.
Error occurred for:
org.mockito:mockito-android:3.8.0
but work for:
org.mockito:mockito-android:3.4.6
We need to update the java version to java 8.
For that please click on File -> Project structure -> app (under Module folder) -> Then select the source compatibility and target compatibility to java 8.
After that you might encounter another error with MethodHandle.invoke and MethodHandle.invokeExact, if you get this error then set the minSdkVersion to 26 or higher

build library ZXing for android project

hi i want to make QR code scanner to my android app using ZXing library
i already success try it with "Scanning via Intent" method before
now i try different approach
my problem is i always get this error
my step
1. download zxing master from here
2. download jar from repository here
3. import ‘android’ folder from zxing-master in eclipse
4. create libs folder and copy core.jar in there
5. right click in CaptureActivity - properties - java build path - library tab - add core.jar path
i don't know why i still get error after add jar path...
i already try clean project, swith workspace, using latest jar file but still same
any idea?
#update #Nickolai Astashonok
eclipse error
'<>' operator is not allowed for source level below 1.7
i try to change java compiler using 1.7 (default 1.6) by
right click project - properties - java compiler tab
but it's seem my target API not fullfil requirment (my API 15)
how to use ZXing in java compiler 1.6?
Update #Sean Owen
when i changed using java compiler level 1.7 and clean project it's says
Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 15
i wanna target my aplication runs for ICS (API 15)
i'm not sure if in 'captureActivity androidManifest using minSDK 19' and 'myProject androidManifest using minSDK 15 will be running well
so i guess i better stick with java compiler 1.6
meanwhile i found this link
based on that link i need to use zxing library version 4.5.1 (java compiler 1.6)
because version above using java compiler 1.7
but i can't find any download link to 'zxing library version 4.5.1'
Your question is not clear, but I think the answer is this: the source code indeed requires Java 7. You simply need to set your IDE project to use Java 7. The supplied Maven build already works correctly in this regard. It is not true that API 15 or any other Android API needs Java 6.
I found 4.5.1 but I don't know how to download it! if you figured it out let me know too please.
https://code.google.com/p/zxing/source/browse/?r=2927#svn%2Ftrunk%2Fandroid
I got the same issue and I solve this by doing:
change the java compiler to 1.7 (like what Nickolai Astashonok suggested)
change the target version to 19 (Android 4.4)
Clean the project again, you will see lots of errors removed but there is still some errors related to missing of CameraConfigurationUtils.java
Please go to below link to download and copy the file into your project as per the path suggested.
https://github.com/zxing/zxing/blob/master/android-core/src/main/java/com/google/zxing/client/android/camera/CameraConfigurationUtils.java
Clean the project again, you should be able to clear all the errors and use the sample application in the 'android' folder.

Importing project gave Unable to resolve target 'android-7'

This app I completed around a year ago (!) but never launched it on the market place. I am trying to open it up in eclipse now to make some small modifications and work on the code a little bit. So I imported it and then found this weird "unable to resolve target" error. It's highlighting every class red in all my 'src' files.
I've looked at a similar question which said to add the line to default.properties file. My project has a project.properties file which has the line:
target=android-7
Any advice how to get this to work? I could always start a new project and just copy all the src files but that would be pretty lame and time-wasting.
One more comment - I'm developing on a new computer and I don't think I have the API level 7. Could that be the problem? I've gone into Window --> Android SDK Manager and the oldest available API it shows is level 8. But level 7 will mean I can target more devices I think so I'd like to go with that.
Thank you for any help.
Well, yes that is your problem. You don't have the API level 7 downloaded. You can right click the project and go properties->android and select another available API. As long as you don't change the min sdk version in your manifest you are still targeting as many devices as before.
<uses-sdk android:minSdkVersion="7"/>
Update
You don't have to do this, but you can get the older APIs on the SDK Archives page
I don't know if there is any official source for the next statement but that is what I found while working. If anybody can complete this with a better answer I would appreciate it very much.
You can compile the code with a newer SDK version as long as you don't use any code not compatible to the previous ones.
Example:
I want my app to be available for API level 7. But i only have API level 15 installed. As long as I keep the minSdkVersion="7" in my Manifest and don't use any resource not available in the previous APIs the app will work just fine on my targeted devices.
For anyone who wants to test their project against an API level that isn't the most recent one, you can just use the SDK Manager to install the old SDK:
In Eclipse (with adt installed):
SDK Manager:
Just check the box of the SDK you want to use to test against your project and click install. You can also remove API's that you aren't using.
Right click on your project then:
Properties -> Android -> Project build target -> Check Android 4.1.2
In your application's manifest.xml file add this tag
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
It's worked for me. Try it.
I resolved this issue by editing my project.properties file
from: target=android-7
to: target=android-19.
I also changed the target sdk version in the manifest file:
android:targetSdkVersion="19".
Yes. I see the same problem when I import the android support v7 project as a library project in my own project,the eclipse says that cannot resolve android16, I find that it's the problem of the eclipse,you can right-click your project which has this problem,and then select properties,the Android pane,there is a Project Build Target pane there,you can see it easily,choose a standard android platform,like Android4.3,not others that start with Google API,I hope that this will help you!
check android:minSdkVersion= in the AndroidManifest.xml
update target=android- in the project.properties if you use Eclipse IDE

xmlvm - import errors compat libs in xcode

Does anyone know where the android compat libary is
located in xmlvm so I could copy it by myself to the project folder because this is
what I guess is missing, also would be provided by target=android-on-iphone but as mentioned below this target isn't available in the current build.
I had absolutely no problem installing xmlvm and getting in touch with the
demo/samples also all the demos worked perfectly for me.
But now im stuck at the last 4 errors in xcode, i migrated my android project via --
skeleton=android:migrate then cross-compiled it via --target=iphone and opened
up the project in Xcode. after few project setup changes the errors went down from
72 to 4 errors ;)
however the errors are importing file not found errors of compat libs, so this
should somehow get to be solved i think...
is it because --target=android-on-iphone wasnt used by me because this option
will copy the android compat libary to the project folder.. well i tried to use this
target mentioned in 2 documentations of xmlvm but in the actual build of xmlvm
this target however does not exist..
How to solve these errors?
Screenshots:
http://img526.imageshack.us/img526/8957/bildschirmfoto20120620u.png
http://imageshack.us/f/138/bildschirmfoto20120620u.png/
From what I can see, it looks like you are using part of the Android API which is not yet implemented.
Unfortunately it seems that you either need to rewrite your application or implement the API yourself.

Libgdx setup UI gives 2 unexpected errors in new GWT project

I have run the setup ui, however, I get two different errors in the -html project than what is described in the tutorial: libgdx tutorial
The tutorial error stated is as follows (which is an error I do not see):
To fix the error of the HTML5/GWT project, go to the "Problems" view, right click the error message "The GWT SDK JAR gwt-servlet.jar is missing in the WEB-INF/lib directory" and select "Quick Fix". Click "Finish".
The errors I have are:
The project was not built since its build path is incomplete. Cannot find the class file for com.google.gwt.core.client.EntryPoint. Fix the build path then try building this project ...
The type com.google.gwt.core.client.EntryPoint cannot be resolved. It is indirectly referenced from required .class files
Is there anyway i can fix this? I just updated my eclipse, I also downloaded Version 18 ADT, revision 19 for Android SDK Tools, and revision 11 for Android SDK Platform-tools.
I had the same problem a couple of weeks ago and got around it by installing the GWT SDK.
I know that the post is old, but while the answer of #Rod was close to resolve my problem, it didn't fully. After installing the plugin in his answer I got 3 error messages instead of two: the same previous ones and a new one.
Looking inside the class that was giving the problem made Eclipse to point straight to the problem: the compiler compliance required to be 1.5 or greater but Eclipse had by default 1.4. I changed it through Window > Preferences > Java > Compiler > Compiler compliance level, where I put the correct one, 1.7, and everything compiled cleanly.
PS: Thanks #Rod
use the http://dl.google.com/eclipse/plugin/4.2 to install plugin on eclipse
instead of http://dl.google.com/eclipse/plugin/4.4 or 4.3

Categories

Resources