Android Studio cannot find a specific method - android

I am getting a compile error in the following code in Android Studio.
Path fileName = Path.of("demo.txt");
String content = "hello world !!";
Files.writeString(fileName, content);
String actual = Files.readString(fileName);
As 'writeString' and 'readString' were instroduced in Java 11, my first guess was it has something to do with that.
I'm using the latest version of Android Studio and have Java 11 installed. Used to have Java 8 as well but I have deleted that already. I'm certain it is just some setting issue or some stucked cache stuff as in IntelliJ it works fine.
I have tried:
invalidate cache and restart
removing the .idea and .gradle folders
I also let Adroid Studio to download Java 11 for itself and not using the one specified by me.
Any guesses?
Thanks in advance!

What Java runtime you have installed on your PC is not relevant. The Java app code is compiled using the JRE API from Android.jar of the targetSDK you have selected in build.gradle in your project. And even more important for executing a method it has to be present in the framework.jar installed on the device you execute your app (which is part of the Android OS).
Using latest Android Studio you can use Java 11 code features but the Android API is still not on the same level as Java 11, therefore you can't use Java 11 specific methods.
Please look at the Android Java API documentation of java.nio.Files which API methods you can use in an Android app.

Related

Use hidden Android functions (#hide) in Android Studio 3.0 - Android 8.1 - API Level 27

I'm developing an Android app which gets signed by the platform certificate.
For testing purposes I'm using the Android Emulator with x86_64 AOSP image, API Level 27, Android 8.1.
The app wants to use a function that has been declared as hidden with the #hide annotation. As expected Android Studio 3.0 can't resolve the symbol.
I could use reflection, but since my app has the rights to use the internal functions, I try to avoid reflection.
How can I make Android Studio aware of the hidden functions ?
I searched on SO and google, but couldn't find a suitable solution, only old ones (two years and older) that doesn't work (anymore).
oat2dex method that doesn't work
You need to be building AOSP in order to force reveal these methods to Android Studio. You can remove the hide annotation in the .java files under framework, and then compile the sdk using the following lines,
lunch sdk-eng
make update-api
make sdk
Then resolve the lint errors as they come, the errors themselves will tell you ways in which you can resolve them. Once this is done, copy the generated sdk folder to the ".Android/sdk/platforms" directory and re-open Android Studio.
EDIT: Just adding that such apps based on a re-compiled sdk would not work on a normal sdk since those functions are not recognized by the normal sdk. So in a controlled environment, you can make it work.

Sharing a common Android SDK on both Android Studio and Eclipse

I am on Windows 8. I have some questions regarding Android SDK:
Can both IDEs share a common Android SDK?
Will there be any issues in updating IDEs?
Generally, yes, it's safe to share a common Android SDK for both Eclipse and Android Studio. Updating IDEs won't affect the SDK at all.
Take note when updating/deleting packages in Android SDK Manager: you might use some packages (e.g. specific API version) in a particular IDE (past example: Android "L" Developer Preview in Android Studio). Updating/deleting them may break the project that use them, and it might be difficult to fix the issue. However, for already-stable APIs like Android KitKat (API 19) and below, there won't be any issue when updating them.
Additional note: Android project created in either Android Studio or Eclipse is not really compatible to each other due to different project structure and technology. Therefor, it's better to always use the same IDE for projects that are created in it. If you want to test both IDEs on same project, it's better to export the project from Eclipse, instead of from Android Studio as it's easier.

How do I create an Android project such that it does not include Android Kitkat, but works on Jelly Beans

I had tried Android studio, android eclipse, and what not, and have constantly been getting R.java file missing error ... that never used to happen with jelly beans .
Is there a way I can use the previous version compilers, as in the ones who don't include any support library for Android kitkat?
You should specify target API version to make it compatible for the specified API level.
cleaning project and rebuilding it will remove the R.java error

the JAR file C:\Program Files (x86)Android\android-sdk\android15\android.jar

has no source attchment. you can attach the source by clicking attach source below.
what should i do. i found different solutions on the web. but it would be nice to find the best solution.
please help out regards
karan
If you use Eclipse , You can find Android Sources Plugin on Adt-addons
In ADT >=8.0.0 you can add Android sources to Android container for all your project with installing the Android source feature using http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/ update site After installing the Android source feature all your existing projects as well as new created projects which is targeted for Android 4.0.1, 2.3.4, 2.3, 2.2, 2.1, 2.0.1, 1.6 and 1.5 will have attached the source jar.
It may not have Android API Level 15 , may be they will update soon

How to load com.android.music code into Eclipse and compile?

I did a git on the com.android.music app and then created a project in eclipse from existing code. I chose 2.1 as the sdk target but I am getting errors trying to compile.
Is the music app referencing code that is not part of the 2.1 sdk? Can someone list the steps for how to compile in eclipse?
Description Resource Path Location Type
ArrayListCursor cannot be resolved to a type PlaylistBrowserActivity.java Music/src/com/android/music line 529 Java Problem
MediaFile cannot be resolved AlbumBrowserActivity.java
Is the music app referencing code that
is not part of the 2.1 sdk?
Absolutely. Most of the built-in apps for Android were created before there was an SDK. You will not be able to build them in isolation from the rest of the firmware without substantial work. Work which, BTW, would be welcome contributions back to the Android open source project, if you were so inclined... :-)
Check the applications manifest file. It will contain an attribute stating which version of the SDK the application was built with.

Categories

Resources