Android Studio ignore deprecated - android

I moved my Eclispe project to Android Studio, but it outputs a lot of deprecated errors when built. I tried some methods, but they don't work.

Try placing this at the top of the methods:
#SuppressWarnings("deprecation")
Example
#SuppressWarnings("deprecation")
public void testMethod(){
...
}
For a brief explaination go to this link:
https://stackoverflow.com/questions/7397996/what-is-suppresswarningsdeprecation-and-unused-in-android
Update:
It seems that there is also some known issues with deprecations. You might want to read this for more info:
stackoverflow.com/questions/26921774/how-to-avoid-deprecation-warnings-when-suppresswarningsdeprecation-doesnt

Related

How to resolve "Obsolete custom lint check" for my custom IssueRegistry written in Kotlin and make it work (Android)

I am trying to implement custom lint checks (using Kotlin). I have set up a module for my custom checks and added classes to test my first lew lint check, mostly following these two tutorials here and here.
So I now have a module, I have a custom IssueRegistry, I've created an issue and a Detector class for it. So far it seems complete. I've added a test to check if my lint check works and it looks alright.
I have added my module to the project by referencing it in settings.gradle like this: include ':app', ':somemodule', ':mylintmodule'
Now if I run the linter using ./gradlew lint I get a lint result file telling me this:
Lint found an issue registry (com.myproject.mylintmodule) which requires a newer API level. That means that the custom lint checks are intended for a newer lint version; please upgrade
Lint can be extended with "custom checks": additional checks implemented by developers and libraries to for example enforce specific API usages required by a library or a company coding style guideline.
The Lint APIs are not yet stable, so these checks may either cause a performance degradation, or stop working, or provide wrong results.
This warning flags custom lint checks that are found to be using obsolete APIs and will need to be updated to run in the current lint environment.
It may also flag issues found to be using a newer version of the API, meaning that you need to use a newer version of lint (or Android Studio or Gradle plugin etc) to work with these checks.
To suppress this error, use the issue id "ObsoleteLintCustomCheck" as explained in the Suppressing Warnings and Errors section.
So it tells me that I am using a newer API verion in my custom lint check, right? This is my custom IssueRegistry (minus some parts not relevant for this problem):
class MyCustomIssueRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(ISSUE_NAMING_PATTERN)
override val api: Int = com.android.tools.lint.detector.api.CURRENT_API
override val minApi: Int = 1
}
From googling this problem and finding this issue I figured I have to override and set the right API version (and maybe the min API?) by overriding these properties like I did above (this version is my last attempt, directly taken from that issue).
So this property can be set to values between -1 and 5, meaning this (taken right out of the lint.detector.api class):
/** Describes the given API level */
fun describeApi(api: Int): String {
return when (api) {
5 -> "3.5+" // 3.5.0-alpha07
4 -> "3.4" // 3.4.0-alpha03
3 -> "3.3" // 3.3.0-alpha12
2 -> "3.2" // 3.2.0-alpha07
1 -> "3.1" // Initial; 3.1.0-alpha4
0 -> "3.0 and older"
-1 -> "Not specified"
else -> "Future: $api"
}
I have tried all of them, plus the one above adding a minApi override too, and I keep getting the exact same result for each of them.
Also I am unable to locate what other API version this is compared with. Is there a place where this is set for the regular linter in an Android project?
It's also unclear to me what I have to do to make sure my changes got applied - is it enough to change some code, then run lint, or do I have to compile the project first, or build & clean?
Following the tutorials, I added my custom lint check by adding this to the app's build.gradle: lintChecks project(":mylintmodule")
Is that even right? The API issue on my registry class shows up no matter if my lint check is referenced (and hopefully used) like that or not. I have also tried the other method described in the first tutorial, adding this task to the linter module build.gradle:
defaultTasks 'assemble'
task copyLintJar(type: Copy) {
description = 'Copies the lint jar file into the {user.home}/.android/lint folder.'
from('build/libs/')
into(System.getProperty("user.home") + '/.android/lint')
include("*.jar")
}
// Runs the copyLintJar task after build has completed.
build.finalizedBy(copyLintJar)
But since I can't figure out how to see if my custom checks are actually run, I don't know if that works as intended either.
So how do I get this warning resolved (since I interpret the text as "As long as the versions don't match I will not try to run your lint check"), and how can I make sure my lint check is actually run by the linter?

AndroidStudio was not right after change code

Situation:
I use Android studio, when i change a line of code in it sometimes it was wrong, the code i just change is not work it still run my old version code.
such as
int a = 1;//old version
int a = 2;//new version
sometimes a still value 1 when i run the new version code.
fix:
I know i can clean the project and restart Android Studio to fix it, but why it's happened?
My Question:
It's just a AS bug or something i was wrong in my project setting?
For more detail example:
I have class a with the method putLog() like below
private void putLog()
{
Log.i("tag","string");
}
Then i find i don't need the Log.i("tag","string") anymore, so i delete it
private void putLog()
{
// Log.i("tag","string");
}
but after i delete it, the log output is still there, my delete is not work.
I restart Android Studio and clean the cache, the log is not show anymore.
That's mainly because i have use multiple-channel gradle script to generate apk, now i remove it, it not show again.

Unable to run Bitmap sample code for Android

I am trying to run the sample from :
http://developer.android.com/training/displaying-bitmaps/display-bitmap.html
However I encountered lots of errors like:
Description Resource Path Location Type
BuildConfig cannot be resolved to a variable ImageGridFragment.java /ImageGridActivity/src/com/example/android/bitmapfun/ui line 124 Java Problem
Description Resource Path Location Type
SuppressLint cannot be resolved to a type Utils.java /ImageGridActivity/src/com/example/android/bitmapfun/util line 99 Java Problem
I ran thru Google but could get nothing. Adjusted the android build target to 4.0.3 (15) but still no clue. Anyone ran this sample successfully?
Thanks.
Here is my solution:
1.Create a new class:
package com.example.android.bitmapfun;
public class BuildConfig {
public static final boolean DEBUG = true;
}
2.Comment the lines that contain "SuppressLint":
//import android.annotation.SuppressLint;
// #SuppressLint("NewApi")
Android developer tools r17 brings a feature to Eclipse where a class is auto built at build-time, called BuildConfig, which contains a constant that can be used by the app developer to sense whether the build is a dev build or a production build. This feature appears to be in the Eclipse integration support, so when using IntelliJ, this useful feature is not available
In gen folder with R.java there should be BuildConfig.java if your program compiled successfully.
/** Automatically generated file. DO NOT MODIFY */
package com.example.android.bitmapfun;
public final class BuildConfig {
public final static boolean DEBUG = true;
}
Clean your project and try to launch it again.
It worked for me.
For me also it is not running directly import to eclipse. Just i put comments which lines is showing errors then it is working fine for me. May be it is not a right answer but we can see the application functionality by running the code so i did like that.

Facebook Android SDK source will not compile with Eclipse Indigo

After finally getting the Android Facebook SDK to properly import thanks to this, I found that eclipse does not recognize the override of onclick in FbDialog.java:
mCrossImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mListener.onCancel();
FbDialog.this.dismiss();
}
});
Nor does it recognize the overrides of onServiceConnected and onServiceDisconnected in the TokenRefreshServiceConnection implementation of ServiceConnection
#Override
public void onServiceConnected(ComponentName className, IBinder service) {
messageSender = new Messenger(service);
refreshToken();
}
#Override
public void onServiceDisconnected(ComponentName arg) {
serviceListener.onError(new Error("Service disconnected"));
// We returned an error so there's no point in
// keeping the binding open.
mAuthActivity.unbindService(TokenRefreshServiceConnection.this);
}
All three methods say, in the warning, that the method must override a superclass method. I have not modified the code at all yet. I checked that Eclipse recognizes the types as the same ones in the respective superclasses, and I have tried pressing control-shift-o to organize the imports, which was a fix suggested in this answer for a similar problem.
These overrides are part of the SDK, not any separate project. I set up the project to use Android SDK 2.2 as was shown on Facebook's instructions, and 4.0.3, which should be, theoretically, compatible with all previous versions. I have yet to get Facebook's own code to work. As a side note, is there a jar I can use instead? It would make this much easier.
Guessing your Project Properties -> Java Compiler Compiler compliance level is set to 1.5, not 1.6 (or higher).
Change this.
Why is javac failing on #Override annotation
The lazy, fast and easy fix is to remove the #Override annotations. The correct fix is to check that the project compiles to Java 1.5 or above, to use "fix project properties" from Eclipse, and possibly to check that the Facebook library project uses the same Android SDK for compiling against, as your project.

Importing projects

I had many Android projects that were working fine in my old pc. now, when I tried to re import them, they are not running. Problem is that onClickListener is not working. Wherever there is onClick method, it throws an Error:
The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
My actual method is :
myBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//my code
}
});
What would be the problem?In every project wherever there is onClick method it shows the same.
Using my supehuman guessing powers I assume that you are using eclipse. Eclipse projects are not portable between machines as they contain absolute paths ( but that does not stop developers from checking them in into source control system ).
Your options are:
recreate eclipse project from sources
create maven build with android plugin and make it create you an fresh eclipse project
spring 150 bucks and buy you license for IntelliJ IDEA ( or just use free community edition which also has android plugins )
simply remove all #Override annotation above the onClick() methods
Goto project menu and clean the project.
Option 1: Simply remove all #Override
Option 2: In Eclipse -> Window -> Preferences -> Java -> Compiler, set "Compiler compliance level" to 1.6 or higher.

Categories

Resources