Android Lint Check for specific project - java

I am using Android Studio for running custom lint check. I have created Custom Lint Library and after the build I am copying customlint.jar by
cp linte/build/libs/customlint.jar ~/.android/lint/
This will copy the customlint.jar to ~/.android/lint/ folder.
Now when I run lint its working as expected.
But when I open other sample projects the custom lint errors are appearing. How to avoid this?
Is there anyway so that customlint.jar is not copied ~/.android/lint/ folder and apply the custom lint checks only to my projects.

I have logged the same issue here
https://code.google.com/p/android/issues/detail?id=233632
As per the reply this feature will be included in future sprints.
Note - Will edit this answer once it is included. Hence marking this as answer.

Related

Gradle: List deprecated features

I am getting a warning about the usage of deprecated features in my build.
Is there a way to list all the deprecated features so that I may go through and update my code?
*clarification
I know I can go to the Gradle documentation and see what is now deprecated, what I would specifically like is a way to go through MY code and list MY deprecated features.
I just faced the exact same problem and running the Gradle build task every time through the command line wasn't the best option for me because, during development, I usually just use the built-in Gradle build task run, so:
I know I can go to the Gradle documentation and see what is now deprecated, what I would specifically like is a way to go through MY code and list out MY deprecated features.
You can do this by adding the mentioned --warning-mode=all flag to your gradle command line options in your Android Studio settings:
This will print the proper warnings for you to be aware of what are the specific deprecated features your app is using.
Also, I know you asked this near a year ago, but, it might be useful for other people facing the same issue.
In order to change the warning verbosity level in the Android Studio IDE, you can add the option org.gradle.warning.mode=(all,none,summary) to the gradle.properties file, which can be found in the root directory of your project.
Add following line to set the warning mode to all:
...
org.gradle.warning.mode=all
...
Use Gradle option -Dorg.gradle.warning.mode=(all,none,summary) to control verbosity, for example, mode all will log all warnings with detailed descriptions:
./gradlew build -Dorg.gradle.warning.mode=all
More details can be found in the official documentation: Showing or hiding warnings
Go to the build.Gradle (Module) file.
replace Compile with implementation.
Sync the gradle file and you will not receive the warning again.

IntelliJ IDEA 12 duplicate class R.java and BuildConfig.java

I use Eclipse for android development and trying to use IntelliJ. I have successfully run the application once. But now, I couldn't seem to rebuild the example Hello World application. What am I missing here? The R.java is not rebuilding anymore. Here is a screenshot of the errors.
And here is my setting
This happened to me because I've marked source folders incorrectly.
Under project settings once you click on particular module, Just check whether you have Mark any additional folders as source folders.
Check the screenshot, By default it should be something like below, All mark as buttons should be unchecked
By mistake I've checked Mark as: "Source" button and I got this error. Just uncheck it.
R and BuildConfig are autogenerated by the android build system. Maybe you somehow copied an autogenerated version of your eclipse project into the idea project and then idea generated second ones. By default, idea will use a folder called gen for these files which is marked as a source folder. Make sure there are no other source folder containings these files.
You can quickly find classes by pressing Ctrl+N and starting to type the name of the class. If you find duplicate results, delete any of them and let idea regenerate the correct ones.
Unfortunately you may not like my answer, but my project is due yesterday and I don't have time to check every setting to fix the issue.
The way I resolved it is to re-create a new project, only copying the src, res, lib etc across. This was painfully difficult and presents other issues (manifest files and run/debug configs) , but proved relatively short as opposed to creating a new project ANYWAY and sifting through build options that may or may not be valid.
I encountered the problem while trying to add the KSOAP2 libs to the IDEA project, and although KSOAP has nothing to do with the problem, I may have imported them in the incorrect manner the first time and created extra self referential dependancies. This makes the most sense, but trying to figure out how to undo it would be next to impossible.
you can try to delete the r and buildconfig files from the com/x/x folder under android -> java
that fixed it for me.

check whether image is used or not in a project

i am new to android. In the project most of the images are used, for some reason some of the images are not used.
But all the images are present in the res/drawable's folder. Going through the code to find which images are not used is a time consuming.
How could i check which images had not used anywhere in the project and remove it.
Solution with reference link could be better.
If you are using Eclipse you can run Lint Error Checking to know which files are used and which ones aren't.
Go to Window->Preferences->Android->Lint Error Checking
If you do any change in the list of enabled checks and click Apply you will be asked if you want to run lint. Click Yes and all the files that you aren't using will be marked with a warning.
Android Lint will do this for you. Check out Lint Tool - I guess, it otherwise depends on which IDE you're using. I know that IntelliJ will mark unused items in the main R.java file itself. But afaik, Eclipse doesn't do this.
Best bet is to use Lint. You can run it from command line also, so doesn't matter what IDE you're using.

After adding library to android project, the XML tag is still "unallowed in Android resource files"

I've been trying to add a library called 'Android Plot' into my project, however I cannot seem to get past this error. Screen shots are below. This library has worked in other test projects I have done before.
I am using Android Studio. Suggestions about how I can get past this would be great. Thanks
Figured it out. AndroidStudio is still in it's "ghetto" stage so if you try to add a library dependency in typical IntelliJ fashion you get a warning telling you that whatever you do in the project/module dialog (which shows up when you select it) actually has no effect on your build and that you must edit build.gradle manually.
In the case of Androidplot 0.5.2 heres what you do:
Add androidplot-core-0.5.2.jar into your /libs dir
In the dependencies section of build. gradle add:
compile files('libs/androidplot-core-0.5.2.jar')
Once you've done this you should be OK.
Nick

Java/Eclipse - No more R file ever

I'm on Eclipse for hours now and I didn't found a solution yet for my problem even after many searches on internet: I have no more R.java file on my projects.
On just created or on my old projects, i don't have R file anymore and I tried so many solutions (uninstall, re-install Eclipse, clean my project, check all my XMLs, fix problem with android tool and so on ...)
Please someone can tell me what to do in this case?
Hey If you just updated to ADT Rev 22 :
I had the problem too. There is a new component in the Tools folder called "Android SDK Build-tools" that needs to be installed.
Step 1
Open the Android SDK Manager
Step 2
Select the newly added Build Tools and install. (If problem stays then go to Project Properties => Java Build Path => Order and Export and check Android Private Libraries, then clean and build project.
It may be necessary to repeat the process, restart the SDK Manager after the update and make sure it looks like this (all tools installed):
More info:https://groups.google.com/forum/?fromgroups=#!topic/android-developers/rCaeT3qckoE%5B1-25-false%5D
Perhaps in Project Properties -> Java Build Path -> Libraries you don't have:
Android 4.2.2 (or other version)
Android Dependencies ?
If so, then right click project - > Android tools -> fix android properties
and see if this library showed up.
Thank you all for saving me! I've spent the whole afternoon on search this error.
Finally, my project works.
By the way, I also encountered one problem which i wanna share with you:
After upgrading, even if my project has not errors anymore. During runtime, it seems it couldn't find the classes from the jars placed in \libs.
Go into Project=>properties => Java build path= > Order and Export.
Please make sure all your jars are checked.
If this problem occurs suddenly in a well working project,
the first step is to find whether the problem occurs only in the current project or in all other projects.
if all other projects in the current workspace are working then 90% problem is with XML / mainfestfile/resourse file that you edited recently.
This error is not shown as red mark we have to find out what we have done recently in these files.
try this
sudo apt-get install lib32stdc++6 lib32z1 lib32z1-dev
it solved my problem
Close your eclipse and after refreshing system, try to open Eclipse again. I think you are using Emulator along with the eclipse. It may be because of the low Memory problem (RAM) of your system. I used to face the same problem when I use Emulator
whenever there is any mistakes in any of the xmls the R goes missing when a build or clean happens so check for any xml errors in your project unless you fix it you cant get back your R on clean or build. fix the xml files and perform a clean you will have the R generated. Also check in File->properties->Builders and see if everything is checked
I was using Eclipse Indigo and nothing I tried worked. I ended up downloading Juno SR2, reinstalling the ADT, and now everything works again.
Reinstall everything and it'll work.. i.e. go back to Google SDK or w.e. you're using and download it.
Update it to latest in SDK Manager.
Go into Eclipse-Project-Prefs-Java build path-order/export TICK EVERYTHING.
problem: No R file get generated.
guess: Try cleaning project if it is old one. Else create new project with no R get generated and with no compile errors but this: no project.apk
In this case you have to check your SDK for the built-tools. May not be installed after updating SDK.
Thus download them if not download here, then put them under directory: SDK/built-tools folder. Lastly, and most important, is to Run the SDK As Administrator. This guarantees refreshing SDK with all packages appearing in it.
Install the SDK-Built-Tools or any missing packages according to the above link and you're done.
hope this helps.
Try one thing, create a new Android Project and transfer all those files which are in the previous project. That worked for me.
In my case there is error due to "&" inside strings.xml file(but error not shown) for declaring string for a array type. Now the problem has been solved as I changed "&" to "and".
So, please make sure that you do not have such silly use of symbols, and clean the project.
I have had the same kind of problem, however Rechecking all XML files in the Resources folder was helpful in my case. I found syntax error in my XML files. Cleaning and building the project again can be helpful sometimes too.
I had the dreaded not more R.java.
Some of the things I've used in the past:
Clean / rebuild (the first thing we all try)
Restart eclipse (optionally reboot pc/mac)
Update both SDK/ADT eclipse plugin to latest version
Create new eclipse workspace and import project
Enable Verbose AAPT build output Eclipse menu>Preferences>Android>Build
Port project to Android Studio / Gradle (this helped my actually see the AAPT error i was getting Error Code:138)
Delete recent XML changes - Ultimately I found deleting recent menu.xml files I'd added and commenting out where they were referenced fixed the issue and I finally got R.java.
I got the error recently and had found no fault in any layout or value file. After a lot of tries I add another Activity and the R.java was build and the error disappeared. I don't know why this occur, but it takes me hours.

Categories

Resources