It is really irritating. I need more time to find some class because of dagger 2.
If you are talking about the generated MembersInjector and Factory classes:
MyClass_MembersInjector.java
MyClass_Factory.java
you can prevent these from coming up in the Ctr-N or Cmd-O dialog by adding them to the ignored files list in File / Settings / Editor / FileTypes and adding the appropriate wildcards to the Ignore files and folders edittext:
*_MembersInjector.java; *_Factory.java; will cause most of the generated classes to be ignored:
Before:
After:
You can even add Dagger*.java to the list if you don't even want to see the generated component (even though this is rather useful for the project).
Update:
If you are talking about not having the classes appear in auto-import/auto-complete this is done through Settings / Editor / General / Auto Import:
David Rawson's answer doesn't help to get rid of not showing _Factory classes when performing Find Usages on the class name. This is what will be shown:
This can be resolved with creating a new scope which will disregard generated files.
Here's the regex for generated files in app module: !file[app]:build/generated//*. But you may as well use "Exclude recursively" button locating the directory you want to get rid of.
Now, change the search scope to newly created:
And this will be the output:
No _Factory classes. You may as well get rid of classes in test packages, thus only classes from production package will be found.
In Android Studio Dolphin there is a new option in Find Usages dialog, so you can ignore usages in generated code.
In Android Studio, go to
File -> Settings -> Editor -> File Types -> Ignored Files and Folders
and add wild cards. Enter apply.
For Hilt, you can add following flags/wildcards *_MembersInjector.java; *_Factory.java; *_Providers.java; *_Bindings.java; *_HiltComponents_*.java; *_Provide*.java
Related
I have a big and messy string.xml file with 3000 records, which most of the values are useless and never used inside code. I want to find and omit those useless records automatically. Is there a way to find useless records inside string.xml file?
Right click on strings.xml file:
Click on Refractor and then on Remove Unused Resources.
Click on Refractor in the confirm Dialog Box.
Menu -> Analyze -> Run Inspection by Name -> Unused resources
Actual resource Is there any simple way to find out unused strings in Android project?
use (Remove Unused Resources) in Android Studio
link
I found the that using the lint check and the translations editor works like a charm.
Go Analyse -> Run inspection by name -> Unused resources.
Here i add a file mask to only show me the strings
After the check has ran go to the Translations Editor, find the key(s) right click and safe delete.
This checks of the resource can safely be deleted and deletes the key in all your locales.
I would suggest the best way would be to load the XML into objects such as Python ElementTree.
import xml.etree.ElementTree
You can then easily Prune all the branches down easily before exporting as an XML file. To deal with XML on a string level is a nuisance.
I'm trying to do the impossible and it doesn't seem to be working. The overall goal is this: I have a Component interface and I would like to show the user a list of classes on the classpath that implement that interface. The trick is, it has to run in Android.
Near as I can tell this is impossible to do at run time. The java mechanism (ServiceLoader) has been intentionally crippled by the Android toolchain, so it doesn't work. Guava doesn't work on Android, nor does ClassUtils, nor does Reflections.
At this point I've been yak shaving for 8 hours strait and there's no end in sight, so I'm looking for alternative approaches. My current thinking is to build a plugin (very much like sbt-spi, but not, because Android hates SPI) that can generate a text file at compile time that lists every class which implements the interface, so that at runtime I can open that file as a resource and then use reflection to start building them. Is that a reasonable idea? How should I go about it? (my current approach is "read the sbt-spi plugin source and try to copy it", but this seems like a scenario where "ask for wisdom" is a better approach)
Got it! I ended up using sbt-spi after all (huzzah not reinventing any wheels!) and just moving the output into the intermediate assets directory as part of the resourceGenerators task:
lazy val androidEntryPoint = (project in file("android-entry-point"))
.dependsOn(core, components, androidComponents)
.enablePlugins(SpiPlugin)
.settings(commonSettings: _*)
.settings(resourceGenerators in Compile += Def.task{
// This task copies the list of Components to the appropriate place to ensure
// it gets included in an accessible place in the APK
val res = collectResources.value._1 // item _1 here is for assets, item _2 is for resources. See the output of sbt "show androidEntryPoint/android:collectResources"
mapExport.value.toSeq.map { name =>
IO.move(target.value / name, res / name)
res / name
}
}.taskValue
)
That said, I'd love to hear a better approach if you can think of one. If none turn up in the next week or so I'll mark this one the answer.
I am trying to rename my eclipse android project. I have tried Android Tools -> Rename Application Package. It gave me an error occurred see log.
I can't find any logs and suddenly this happen my project structure shows some blank and garbage packages as shown in picture.I tried deleting it but deleting them deletes my source code too.Any idea will be very helpful..
You can rename classes, packages and projects by right clicking on the class/package/project and choose: Refactor -> Rename. Check the Update references box to make sure all references to the project/class are also changed.
This behavior is totally ok.
A java package corresponds with an folder.
When a package/folder is empty eclipse will show it as "white boxed" without content (no arrow).
Example:
The class "AClass" in "com.me.pckg" corrensponds with
com/me/pckg/AClass.java
This means folder "com" and "me" contains no files. Eclipse represents this a "white boxed" packages (com and com.me). Package "com.me.pckg" is not empty.
Aware eclipse does not show the package structure NOT as hierarchical as you expect it in a file system view.
Vice versa if you put some file/-structure in your project eclipse will show new folders a packages. This happens after a refresh or a restart of eclipse, the later may be perceived as a sudden action.
If you want to change the type in "com.demo.alaramdemo" use Pieter12345 answer(, or just change the name of the folder in the file system)
If you want a more file system like view within eclipse use the "Navigator"-View
Finally i got the answer to this, With the help of a post above by Stefan
and a solution mentioned here on below link http://www.coderanch.com/t/105581/vc/Eclipse-hide-empty-packages
actually i had to create filters available on a inverted triangle in package explorer header.
In that u have to check filter of empty package , empty parent package etc
it worked for me.
Thanks all for the help ... :)
I've found an unused string resource, like:
<string name="obsoletestring">my name is null!</string>
However it is in tens of files, of different languages, in different strings.xml files in values, values-af, values-be, etc folders.
I must have missed something not to know any way to do this in Android Studio other than modifying it by hand one by one.
tl;dr How to delete an unused string resource for all configurations?
To identify all unused resources:
Open Menu > Analyze > Run Inspection by Name...
Select "Unused Resources"
Make sure Whole project is checked, then press OK.
Look through the list. You can always rerun the Inspection with the Rerun button.
There is no really easy way in Android Studio (v 1.0) to remove a resource string for all locales. However, you can search and replace in files. Fortunately, the translation files use only a single line in most cases so this works pretty well.
In Android Studio:
Start with no changes pending in your source control (makes it way easier to check and back out if this goes wrong).
Open Menu > Edit > Find > Replace in Path...
In Text to find: .*name="obsoletestring".*\n
In Replace with: (empty)
Check Regular expression
Press the Find button.
Inspect the results. If okay, press the "All files" button.
You will probably have to remove the comment in res/values/strings.xml manually.
Make sure your project still builds.
Take a look at the diff of your project in your source control to ensure the change is really what you intended...
It is now possible inside Android Studio.
After Lint checks you see an option on the right Remove All Unused Resources!
To Delete a single string resource across all locale files, you can use the "Translation Editor".
1. Right click on the res directory to open the translation editor.
2. Select "Show All Keys" selector, and choose "Filter by Text". Supply the name of the resource that you want to delete.
3. Select the resource, and click on the "-" button
Until IDE support comes along, something along these lines will work:
find -name strings.xml|xargs -rd\\n sed -ri '/"string_to_delete"/d'
In Android Studio 2.3 it's possible to remove all unused resources.
Open any *.xml in your res/values/ directory
Right click on any item's name
Refactor -> Remove Unused Resources...
Menu -> Analyze -> Run Inspection by Name -> Unused resources
From the results select all string resources that are unused.
Right-click highlighted rows and choose "Suppress with #SuppressLint(Java) or tools:ignore(XML)". This will add the attribute tools:ignore to all strings in all string files.
Menu -> Find -> Replace in Path
Text to find: ^.*?tools:ignore="UnusedResources".*?\n
Tick regular expression box
Use Scope: Custom
Open custom scope editor and add pattern: file[app]:src/main/res//strings.xml
Find
Etc.
Unfortunately, You have to do it manually.
Check this answer to understand what exactly should you do to get rid of them using Eclipse
If you are using Android Studio find them in the whole application and also remove manually .. Check this answer
Beware that the REMOVE UNUSED RESOURCES command cannot recognize a programmatically accessed resource as a used resource (such as getIdentifier(..) etc.).
So, if you do access resources that way, it is highly risky to use that command!!
In fact, Android Lint should report about the unused resources, but you can also try with this nice plugin.
How do I fix this? I already tried removing the R.java and cleaning the project via eclipse, but it doesn't help.
FYI I am trying to get PhotoStream from here: http://code.google.com/p/apps-for-android/, but so far it has been very difficult to get things work.
Okay..... 5 mins later google tells me the correct answer...
http://www.fairtec.at/en/it-blog-mainmenu-16/168-the-type-r-is-already-defined
I just didnt search hard enough.
"The type R is already defined"
That's the message you get in Eclipse if you try to build the Funambol Android Sync Client.
Reason is that you have checked two Builders that try to generate the same class.
You just have to uncheck the Java-Builder from Project->Properties->Builders.
Then the application even works fine in the Emulator.
Delete the R.java from the src folder and rebuild the project. This file will be automatically rebuit during this process.
http://www.fairtec.at/en/it-blog-mainmenu-16/168-the-type-r-is-already-defined
click right to project click properties
Project->Properties->Builders.
unckeck java Builder
delete file R.java
You may want to change your package names. It looks like you are using a 'PhotoStream'.jar which has it's R.class defined at the same package structure as you.
Here is a link to the R.java from the project on Google Code. Notice you are using the same package:
http://code.google.com/p/apps-for-android/source/browse/trunk/Photostream/src/com/google/android/photostream/R.java?r=83
I had the same issue when I imported a project from work. Turning off the Java builder as suggested in the article you found fixed my problem, but when I made code updates they were not reflected in the running app. In my case there was an R.java in my source which I deleted and that fixed my problem.
In my case,
as i m not using any IDE for programming but using command line Android..
i had two xml files, one in layout and other in layout-land. i was using same id "XXX" for both but while declaring i made small mistake
android:id="#+id/XXX" (in layout xml)
android:id="#+id/XXX " (in layout-land xml)
please observe extra space in second id declaration, so while creating R.java they were different and in R.java i had
public static final int XXX=0x7f040046;
public static final int XXX =0x7f040045;
which are same, so please be aware of extra spaces. Thank you