Find all issues saying `require API level` in Intellij / Android Studio - android

I want find all issues saying call requires some API level in whole project.
Call requires API level 21 (current min is 19):
android.content.res.Resources#getDrawable
I could see its issue id is Issue id: NewApi. But I can not find a inspection name for same. Basically I want run inspection by name to get all these issues.

You can find the name in Settings -> Inspections (there is no filter by id, though)
In your case it's Calling new methods on older versions.

its very Simple
In Android Studio Right click over any class file.
Select Analyze and select Inspect Code
Under the Popup window select the hierarchy like Whole Project, Module App
or specific file.
Click OK
it will generate the report, by this report you can find all locations of implementation.

Related

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.

Adding Support Libraries to Android project

Why am I having such a hard time getting into the swing of Android development? I've been developing in various languages over the years and, for some reason, just can't seem to get beyond that "jeez-i-still-feel-a-total-noob" stage with Android.
So I'm trying to add an Action Bar to my Android 2.3.3 project. No problem, right? The Android developers website has a nice and clear article explaining exactly how to do it. Of course it involves adding the appcompat v7 support library. No problem, even this is documented step-by-step on this page. But, as with just about every such exercise in Android, I find that you can do exactly what the page tells you to do, it still won't work without significant amount of Googling to fix the errors that you encounter afterwards.
So I've followed the steps under "Using Eclipse" in the section "Adding libraries with resources" in the above link. The first error I get is Unable to resolve target 'android-16'. No problem, this one I could figure out for myself but I'm curious, is there anything in the documents I've been following that would have suggested to me that I need Android 4.1.2 (API16) installed? Did I just read right over it or should I have known by myself that, to do what I'm trying to do, I would need API16?
Never mind, at least I can fix that but then I get a new problem. As soon as I add the android-support-v7-compat library to my project and click the OK button, the console output lights up with errors, the first one being:
C:...\android-support-v7-appcompat\res\values-v14\styles_base.xml:24:
error: Error retrieving parent for item: No resource found that
matches the given name 'android:Widget.Holo.ActionBar'.
and the other 60 odd errors are similar but for different given names.
I would really appreciate if anyone could help me out here. Obviously I'd like to know how to solve this particular problem but if anyone could give me some tips on how to get past this very frustrating stage of learning this new development environment, I would be ever so thankful. What is it that I should have done differently not to run into these kinds of errors, other than following the instructions on the Android Developers website step by step?
OK, I guess I should post an answer as I've eventually managed to solve my own problem.
It turns out I have to use a build target of Android 4.2.2, regardless of the fact that I'm specifically developing for Android 2.3.3 - I mean, that's why I'm using support libraries after all. I imagine it might be possible that some other lower target (but higher than 2.3.3) would still work I just used the highest one I have installed and it solved the problem.
How I was supposed to know this from following the step-by-step instructions on the Android Developers website is a mystery to me. The reason I decided to try changing the targetSdkVersion was because of the final section in the page referenced in the question. It reads "If you are increasing the backward compatibility of your existing application to an earlier version of the Android API with the Support Library, make sure to update your application's manifest." Now I'm not increasing the backward compatibility of my existing application. I'm changing an existing application that targets 2.3.3 to be able to include an Action Bar (seems more like "forward compatibility"). I tried upgrading the targekSdkVersion though as I was out of ideas and lo and behold, it worked.
Don't know if it helps you at all, but I've been struggling with a similar issue for several hours and finally managed to resolve it. In my case, inside my own project's styles.xml file, I was referencing the AppCompat style in the wrong way in the parent attribute.
I was using:
<style name="AppBaseTheme" parent="android:Theme.AppCompat">
where I should have used:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat">
My mistake was in the reference to the theme.
I found that setting the Android target to 2.3.3 for the library project android-support-v7-appcompat solves this issue. You don't need to set your project's target higher, but the library's target lower.
You have pinpointed the all important document and the relevant section "adding libraries with resources":
http://developer.android.com/tools/support-library/setup.html
The error suggests that your project is not able to find these resources. Please double check the following :
You have checked "is library" on the library project
You have exported the jars IN THE LIBRARY PROJECT as described in that section
You have added the library project as a reference to your app project
You have added the android-support-v4.jar to your libs folder in your app project
If this is all definitely correct, check eclipse for any error messages - is it the library project or the app project that lights up like the proverbial Christmas Tree ?
First of all check if you have done all the described steps as explained on the developers site. Then, for the errors :
Unable to resolve target 'android-16'
Make sure that you have installed API16, this errors occurs if you have mentioned your targetsdk to 16 in your Manifest while the sdk for API16 is not installed. You can either install the API or edit the targetApi of your project to the minimum required version, for the support library you are using I think API 11 is the minimum required android version.
android:Widget.Holo.ActionBar
This error should also be fixed once the targetsdk is fixed in your project. Since to use Holo.ActionBar you'l need to target your project to minimum supported api level ie. 11 or higher.
I met similar problems. Using API 18, ADT.
To solve the "Unable to resolve target 'android-16' problem", I remove the import lib project and repeat what the tutorial says.
Then I found I couldn't really "add" the library to my project. (The instruction "In the Library pane, click Add." there is not that detail.
1. In your project -> properties -> Java build path -> Libraries -> Add Library... -> Android Classpath Container -> Select the lib project
2. In your project -> properties -> Android -> add... -> choose the lib -> apply
cheers
Here is how I avoided the error, " Unable to resolve target 'android-16'", when adding v7.
First, I followed the instructions for adding support libraries with resources in eclipse. Following step 4, I clicked Finish. That's when I saw the error message, android-support-v7-appcompat] Unable to resolve target 'android-16'.
Second, I read this post. I also opened the download manager, but did not need anything updated. In order to make sure that I followed the steps exactly as correctly as I could, I deleted the android-support-v7-appcompat project and started over.
This second time I didn't check any different boxes, after all. But, I also got no errors at step 4. Who can say why?
Thanks, Dewald, you expressed in this question the same frustration I have. Is experience the only way out?
If some of your resource xml files cannot find their respective AppCompat references, make sure you also add the support libraries to your project properties. You do this by:
1.) right clicking on your project in the project
2.) Select properties. (Bottom of the menu)
3.) click Android on the left hand side menu of the new pop up window
4.) In the libraries section, click the "add button"
5.) Select the respective libraries. (If none show up, check to see if they are already displayed in the "libraries" window of the pop up menu. If there is a red x by the desired library, try and resolve that issue first.)
6.) Once there is a green checkmark next to the desired libraries, make sure the "Is Library" option in the libraries section IS NOT selected.
7.) Click apply.
8.) Close the pop up menu.
If this doesn't work, let me know and I can help you out. I spent three hours on the problem so I know pretty much all the possible things that can go wrong with the set up.
Go to Project -> uncheck Build Automatically
Go to Project -> Clean... , clean both the library project and your app project
Export your app as a signed APK while Build Automatically is still disabled

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

Eclipse opens wrong source file on exception

I have several Android projects in an Eclipse workspace:
a stand-alone application project with a class my.package.Foo
a library project with a different class my.package.Foo
two application projects that depend on the library project and contain no source code
The problem comes when working with one of the applications built on top of the library project. When it crashes (sadly, a frequent occurrence), I double-click on a line of the stack trace in the logcat to go to the relevant source. The problem is, if the line is for Foo.java, Eclipse always opens the source from the stand-alone project. The only way I can direct Eclipse to the right source is to close the stand-alone project, which is somewhat inconvenient.
Is there any way to get Eclipse to pay attention to which application actually crashed when it looks for the relevant source file? I assume that this is some sort of classpath problem (similar to that described in this post). However, I don't see anything in the Android run configuration properties for modifying the class path. Eclipse always seems to run through the workspace projects in alphabetical order by name and opens the first my/package/Foo.java it finds.
I'm using the latest Android ADT and SDK versions.
Per the link provided in the comment by #blessenm, this is an issue with logcat in Eclipse. We should see a fix in Release 20 of the SDK tools. As can be seen here, the patch that fixes it has been completed and is in line for final approval.
Meanwhile, the best thing to do is to change the logcat preferences (Window -> Preferences -> Android -> LogCat) so that the double-click action is "Go to Problem (method declaration)" instead of the default "Go to Problem (error line)". This isn't foolproof: it will at least open the file but if there are multiple methods with the same name, it will go to the first method, regardless of signature. (When the fix is incorporated, there will be no need for options for double-click action and it should disappear from the preferences.)

Lint for android in Eclipse gives wrong results

If I run "lint ." inside project directory I get the expected warnings, but if I run it from inside eclipse I get nonsense errors and warnings, for example:
The resource R.array.settings_derivatives appears to be unused [in fact, it is used]
The x.y.z is not registered in the manifest [in fact, it is registered]
Call requires API level 3 (current min is 1): android.view.SurfaceView#isInEditMode [in fact minSdkVersion is set to 7]
edit: If I create a new workspace and import the existing projects I get the right errors
There seems to be an issue, when the project directory is not directly under the workspace directory.
As of today the bug should be fixed in release 20:
http://code.google.com/p/android/issues/detail?id=27527
Edit:
If necessary you can make a softlink into the workspace.
The problem was solved by switching workspace to a fresh one. It probably was a problem with settings left over from previous lint versions
I solved the same problem using this:-
Right click on the project folder > Android tools > Clear Link Markers
"Run Android Lint" makes some markers and the markers cause this error.
"Preference --> Android --> Lint Error Checking", search issues "NewApi", and you can see the settings.
This check scans through all the Android API calls in the application and warns about any calls that are not available on all versions targeted by this application (according to its minimum SDK attribute in the manifest).
If your code is deliberately accessing newer APIs, and you have ensured (e.g. with conditional execution) that this code will only ever be called on a supported platform, then you can annotate your class or method with the #TargetApi

Categories

Resources