How to specifiy the java/android platform with IntelliJ-IDEA? - android

I wanted to try out IntelliJ-IDEA but my experiments failed in a very early state. The Problem is that I found no way to set the Java platforms to be used.
Standard Java fails #Override annotation as IntelliJ-IDEA fails to to use the installed Java 6.
Android tells me to set the Android platform - only there is no setting so be seen to set any platform.
So what am I missing here?

Use File -> Project Structure menu.
There you can specify jdk(by New button you can add your installed jdk).
In your android module settings(Project Structure : Modules) click the detected facet( Android ) and there choose your platform.

Please refer to the official documentation. Also be aware of this issue.

Related

Finding duplicated code (Kotlin) in Android Studio

Is there a way to find duplicated (Copy/pasted code, repeated code) Kotlin code in Android Studio?
I have Android Studio 4.0 but can't find this "Duplicated code fragment" option.
Are there any Android Studio plugins that do this job for Kotlin?
You can install the sonarLint plugin.
It has many rules which are executed on source code to find possible issues like bugs or code smells.
This is done with the rules provided by default.
Other example of repetition:
Just need to install the sonarLint plugin in Preferences/Plugins:
A more advanced tool you could check is Gradle CPD plugin.
This is a Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD). You can find information about how to install it and how to use it in the same readme of the repository. CPD supports Kotlin since v6.10.0.

Cannot find annotation method 'anyOf()' in type 'RequiresPermission':

I am trying to port an Android app in Android Studio to Visual Studio 2015 / Xamarin. I try to run the project and I get:
Android application is debugging.
The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).
Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.
I added [Activity(MainLauncher = true)] to the main class and checked Build->Configuration which appears to be correct, but these have no effect.
I get this warning:
Cannot find annotation method 'anyOf()' in type 'RequiresPermission':
class file for android.support.annotation.RequiresPermission not found
MyApplication.Native.Droid C:\Users\allelopath\AppData\Local\Xamarin\GooglePlayServices.Maps\8.4.0\embedded\classes.jar(com/google/android/gms/maps/GoogleMap.class)
I also get this warning:
Warning
Found conflicts between different versions of the same dependent assembly.
In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts;
otherwise, add the following binding redirects to the "runtime" node in the application configuration file:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly><assemblyIdentity name="System.Net.Http" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding>
Acquaint.Native.Droid
I double click as it suggests and it asks:
Do you want to fix these conflicts by adding binding redirrect records in the application configuration file?
I click Yes. This ultimately has no effect, after rebuilding and trying to run, the warning reappears.
I unstalled the app on the device, which had been there from running it on Android Studio, but this had no effect either.
What can you suggest?
For the first problem I would right click on your solution, go to Configuration Properties and ensure that all of the correct projects are being built and that your android project's Deploy box is checked. This is just a bad Xamarin tendency.
I have the second warning myself and it is simply because the Android Support Library requires you to compile against sdk version 23. The Google maps package must use these new annotations. I haven't encountered any problems because of this error, with a minSdkVersion of 15, so I just live with it.
I also have the same dependent assembly warning and what I think is happening is I have one project which is using a newer reference to .net primitives than whatever .net http is using. Just a guess but I am also not worried about making this happy.

Android Studio Removing Code Redundancies

I'm trying to remove redundant that I've in my project.
This option is part of the ReSharper Tool, but I didn't found any hint about if this tool is available in Android Studio.
I found it. It's already built-in feature in Android Studio regarding to this post by Andrey Cheptsov.
Just do this : Analyse -> Code Cleanup -> Specify the scope of the clean

Using serial for android library

I'm trying to implement this https://github.com/mik3y/usb-serial-for-android/blob/master/UsbSerialExamples/src/com/hoho/android/usbserial/examples/SerialConsoleActivity.java in my project but there is something wrong with this sample.
Line 121:
sDriver.setParameters(115200, 8, UsbSerialDriver.STOPBITS_1, UsbSerialDriver.PARITY_NONE);
Why I can't see this method setParameters()?
I had the same problem when I tried to use the example project. The problem I had was that I was using usb-serial-for-android-v010.jar that you can download from the git repository. I think it was created using an older version of the project and doesn't support some of the newer features like setParameters. If you downloaded the example project there should be a folder inside called UsbSerialLibrary. Import that into your IDE and add it to your build path: (Eclipse) Properties>Java Build Path>Projects>Add. This should let you use setParameters.
Also, the API was recently refactored so you may want to look at that.

Issue in dropbox-android-sync-sdk-1.0

Below code in onClickLinkToDropbox() method in HelloDropboxActivity class of "Hello Dropbox" example in Android Sync SDK show error as
The type android.app.Fragment cannot be resolved. It is indirectly referenced from required .class files.
How can I solve this ? I'm using Android 2.3.3.
mDbxAcctMgr.startLink(this,REQUEST_LINK_TO_DBX);
This seems to be the compiler being unreasonably picky during overload resolution. I see two possible solutions to this:
Build with a later SDK version (11 or later). You only need to change the SDK you use to build (set the target in Eclipse project properties dialog, or target=android-11 in project.properties). You can leave both minimum and target set to 10 in your AndroidManifest.xml, so your app will still be compatible with older versions. In general it should always be safe to build with the latest SDK. You'll get warnings if you use APIs which don't exist in your manifest-defined target.
Work around it by forcing the overload resolution like this:
mDbxAcctMgr.startLink((Activity)this, REQUEST_LINK_TO_DBX);
If you're not already using it, you will also need the Android Support library. In Eclipse, open the context menu on your project and select Android Tools → Add support library... and follow the prompts to add the library to your project.
https://www.dropbox.com/developers/sync/tutorial/android

Categories

Resources