"Code Cleanup..." feature of Android Studio v2.2.2 - android

In Android Studio v2.2.2, Code Cleanup feature available under Analyze option.
Analyze >> Code Cleanup
What this option exactly do with code ?
Please explain in details.

When you clean up your code using 'Android Studio', It start inspecting code defined rules.
For list of defined rules check, File -> Settings -> Editor -> Inspection.
(For Mac, Android Studio -> Preferences -> Editor -> Inspection)
Here you can find all rules like,
non-used variables,
non-used import,
Abstaraction issues,
Code style issues,
Java Beans issues etc.
After inspection of code, Android Studio will remove such code from your files that is not necessary. It is called cleaning up code.
There are many plugins available for it. As Android Studio support by default, You can format and clean your code using this feature.

Related

How to share Kotlin formatting conventions in project for Android Studio and IntelliJ IDEA?

I'm looking for some support and tips on how properly share the Kotlin formatting conventions in an Android project that is being opened in both Android Studio and IntelliJ IDEA by different team members. I'd like to force the usage of Kotlin coding conventions; and I'd like to avoid asking every developer in the team to change their settings in IDE configuration of the Code style.
So far I've been following 2 approaches:
Commit the .editorconfig file to the repository - but this file does not cover all the settings that we would like to share between developers and IDEs.
Commit the files that are located under .idea/codeStyles/ directory in the root folder of the project. This seems to cover the cases that were not handled by 1), but the Project.xml files seems to be altered every time when the project is opened in IntelliJ (if the Project.xml has been created in Android Studio, and I suspect vice versa as well).
Moreover, I can see some inconsistencies when I try to format the same Kotlin source file in Android Studio and IntelliJ. Could it be that both IDEs contain different sets of rules of Kotlin official coding conventions?
Another way to share formatting options is via code style xml.
After you set all the options in your IDEa (in Editor -> Code Style -> Kotlin), click gear button next to Scheme and choose Export -> IntelliJ IDEA code style XML like shown on a picture:
Share this file with your colleagues, and they can import those settings in a similar way by clicking Import Scheme.... Since Android Studio is based on IntelliJ IDEa, it will understand this file.

Context of lint.xml and inspection profile

In Android Studio there is the lint.xml configuration and ./idea/inspectionProfiles/.xml manageable via Settings => Editor => Inspections. I understand lint.xml is used by lint command line tool and the inspection profile is used by Android Studio IDE.
The official documentation is here. I also found this post How is lint integrated with IntelliJ inspections in Android Studio? and this post Android lint on command-line missing issue groups (versus options available in Android Studio).
This answer has a good example of lintOptions{ } block in build.gradle.
Yet there is some information missing.
Are numbers and names of the rules the same?
Is there a (simple) way to convert inspection profile to the lint.xml and vice versa?
Are they completely separated or are there cases when one is included in the other?
Which one is executed apart from cases metioned above (e.g. analysis on commit)?
I can sum up my research so far.
1.) Inspection Profile is extending lint.xml, so the number of lint.xml rules is smaller than the number of Inspection profile rules.
The current lint.xml ruleset can be found here.
2.) When you have defined a lint.xml, in your Android Studio you can go to File => Settings => Editor => Inspections and use the Manage => Import dropdown towards your lint.xml. This will set all rule outside lint.xml to be deactivated.
I don't know of any way for convert from InspectionProfile into lint.xml.
3.) See 1.), Inspection Profile is extending lint.xml.
4.) As Inspection Profile is locally used and inside Android Studio, it is executed during runtime in the editor and on commit when analysis is checked.
Your lint.xml is usually located in the project's root and submitted into SVN/GIT. Then your configuration server (Jenkins, QuickBuild etc.) can have a designated task to run this lint.xml and process its output.
Additional, helpful things:
You can run gradlew lint from the Terminal inside Android Studio. It will create a html page at /build/outputs/lint-results-debug.html or at any file position specified.
When you open a lint.xml file in your Android Studio editor, a lot of content assist is provided for the rules. Nevertheless there seems to be a gap in the rulesets, as e.g. Convert2Lambda is in the example lint.xml, but not in the official documentation.
Despite that it is generally a bad idea to put ./idea under version control, for team distibution you can submit your Inspection Profile at /.idea/inspectionProfiles/MyInspectionProfile.xml and put every other file inside /.idea on ignore. There is an article on this topic I cannot find anymore, but this solution works like a charm for my team.

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

how to disable missing '#override' annotation check in Android Studio

I want change codes, in run time Compile classes. but I can't change codes of this classes.
I search and realized that i have the option to deactivate.
This option's path in eclipse is : windows - preferences - java - compiler - errors/warning .
but I can't find this path and option in last version on Android Studio (1.2.1.1).
please show me this option (missing '#override' annotation), in last version of Android Studio.
it is in Settings -> Editor -> Inspections. By default it should be disabled

How do I force eclipse to update the apk on my hardware device with each build?

If I change some code, save, and Run, it runs the last version of the program, not what I just saved. The only way I can make it update is if I Clean the project, Build the project, and then Run the project. Is there some way to avoid this tedium?
I spent some time create two dummy projects (one Android and one Java) and have a play with it, and finally come up with a workaround which is not used very often but able to solve your requirements.
First, I will explain your question a bit more (based on my understanding and what I have tried) so that other people can have a more clear understand about what is happened here.
According to the conversation in comments:
could you tell me what you have in following setting: project->properties->Builder ? – Sudar Nimalan
#SudarNimalan: I am not sure this is what you are asking, but: there's text that says "Configure the builders for this project", and under it is a single option, "Java builder", which is selected (checked). – shino
for android project, there should be, "Android Resource Manager", "Android Pre Compiler", "Java Builder", "Android Package Builder" in this order, chould you add those and try? – Sudar Nimalan
#SudarNimalan: I owe you an apology; I do have those four components. My "project" is split into 4 projects - "core", "core-android", "core-desktop", and "core-html". It's a little weird because I set it up with the libGDX project setup UI, and I was looking at the 'core' project when I answered your question. My 'core-android' project has all four (in that order), and it is the one that has the problem in my question. – shino
Scenario:
You have 4 project:
core: a regular java project (common pure java code here)
core-android: an Android application project.
core-desktop: not related to question so ignored.
core-html: not related to question so ignored.
The core-android project has dependency on core project, by adding core to core-android's build path (Properties -> Java Build Path -> Projects -> Add ...) and export list (Properties -> Java Build Path -> Order and Export).
Problem (Not Really):
Change some code in core and save it, run core-android, eclipse install last compiled apk, not the new one with change.
Reason:
The is the expected behavior, the way you used to reference core project in core-android only create a weak link (or something sort of) between core and core-android, the core-andorid's auto-build script doesn't aware any changes made in core. You have to clean the project (only need clean core-android project) so that Eclipse can delete the existing apk (under bin directory) and re-generate the apk (with the latest code changes from core).
See Xav's comments below, Android SDK tools should aware changes from plain Java project under project build path, and it does not behaviour this feature normally at the moment.
Note that if core is an Android Library project, then there is no problem and your core-android project will aware any changes in core project (java code, android resource and etc), if core is only used in core-android, this could also be a workaround: turn Java project core into Android library project.
Workaround (Eclipse Link Source):
There is another way (not commonly used) for adding soft link between projects:
First, you need remove core project from core-android's build path, this will also remove it from Export and Order list.
Right click core-android, choose Build Path -> Link Source ... Add ../core/src as Linked Folder Location and src-lib1 as Folder Name,see screen screen in the end.
This create a symbolic link src-lib1 under core-android in Package Explorer windows point to core's src foder, in the file system, you still have two separate project folder. Now if you change some code in core and run core-android, Eclipse will build and install latest apk. No need to clean core-android project.
Link Source Window:
Final look in Package Explorer:
You should always consider the normal approach as first option, after all, manual clean project is not a big deal compare to the unusual approach I described above.
Please follow this steps..
1. Project--> Build Automatically been checked??
2. Please following setting: project->properties->Builder like that?
Check below image.
And Also Check Below Settings.
Also Check Below Image
IF problem continues then please Update your ADT & SDK.
Hope it works for you .
Navigate to Windows->Preferences->Android->Build. Make sure that the checkbox "Skip packaging and dexing..." is NOT checked.
The Problem is the In your Eclipse, go to Project Properties - Builder, There is one CheckBox with AndroidPackageBuilder that is required to be Checked True. Now everytime you will do any changes in you project that will be reflected in your build and the Compiler will never say that
"Application Already Deployed, No need to Reinstall"
This will work evenif you dont have selected Build Automatically, Because everytime you run by clicking Run icon or Ctrl+F11 that will first Build the Project and Then Run it. So The requirement is just to Enable the Android Package Builder
You won't believe how easy and silly is the solution
On Eclipse,
go to Window-Prefences->run/debug ->launching
And then, on Save required dirty editors before launching :
choose the Prompt option,
Apply and OK

Categories

Resources