Android studio - custom 'Remove unused resources' - android-studio

I'm trying to remove unused string resources.
In android studio, there is an option to remove unused resources. My issue is that I have a separate file that contains strings keys. At runtime I'm parsing this file and then fetching strings based on these keys. When running the remove unused resources option in android studio it can't detect that these keys are being used because they aren't referenced from code or xml.
Is it possible to somehow setup a rule in android studio to take in consideration this custom file I have?

I ended up writing a script that parses the custom file and creates an enum that holds a reference to the strings that should be kept. Generated enum looks like this.
enum class StringsToKeep(#StringRes stringRes: Int) {
STRING_KEY(R.string.string_key),
STRING_KEY_TWO(R.string.string_two),
}

Related

Hide Gradle pre-compiled plugins generated sources in Android Studio

I have a gradle pre-compiled script plugin inside the build-logic project, which I use as an included build on android-project. The Android project tree view displays also the generated sources for some-plugin which I want to hide.
With this default setup, AS can resolve a reference for the extension detekt because is a generated accessor.
I can hide the generated sources by applying the idea plugin to some-plugin and excluding the generated-sources directory as follows:
// build-logic/settings.gradle.kts
gradle.beforeProject {
pluginManager.apply("idea")
configure<org.gradle.plugins.ide.idea.model.IdeaModel> {
module {
// Exclude generated sources from AS project tree
excludeDirs = setOf(
file("${buildDir}/generated-sources/kotlin-dsl-plugins/kotlin"),
file("${buildDir}/generated-sources/kotlin-dsl-accessors/kotlin"),
file("${buildDir}/generated-sources/kotlin-dsl-external-plugin-spec-builders/kotlin")
)
}
}
}
Which effectively now take away the generated sources from the Android view:
But as you can see, the detekt extension is not longer resolved by AS. Build compiles successfully.
How can I hide the generated-sources files but still allowing AS to resolve references to the hidden files?
You can create your custom files scope and even associate with a color where you can exclude the needed directories and set it for the Project tool window.

What is the use of com.diffplug.spotless plugin in Android Studio?

I am working with Jetpack Compose and I came across "com.diffplug.spotless" plugin in the app's build.gradle file of many examples, but I am not sure if I need it in my project. Can anyone explain the purpose of using it in the Jetpack compose projects?
''' apply plugin: "com.diffplug.spotless" '''
Spotless: Keep your code spotless with Gradle
While working, Many a times you will get formatting issues at the stage of every commit like removing empty lines, cutting white spaces correct, indentation and other minor formatting mistakes.
Using tool/plugin called “Spotless” will reduce time in addressing code review comments.
Spotless provides support for a variety of languages.
Spotless consists of a list of format and each format has:-
1.a target (the files to format), which you set with target.
2.a list of FormatterStep, which are just String -> String functions, such as replace, replaceRegex, trimTrailingWhitespace, custom, prettier, eclipseWtp, licenseHeader etc.
To start integration with Gradle:-
1.Add the following dependency to your build.gradle file
classpath(“com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion”)
2.Apply the following plugin
apply plugin: ‘com.diffplug.gradle.spotless’
3.Applying spotless to your gradle file in Android Java source
spotless {
java {
// ...
target '**/*.java'
// ...
}
}
Note:- Be sure to add target '**/*.java' otherwise spotless will not detect Java code
inside Android modules.
For more detail you can refer this link : 1

Visual Studio 2019 - CMake Linux - Where to get list of macros?

When working with the CMake Linux project in Visual Studio 2019, every json file (e.g. task.vs.json, launch.vs.json) magically uses macros like:
${workspaceRoot}
${env.xxx}
${debugInfo.xxx}
${cmake.xxx}
How can one know the full list of options when documentation is scarce, and IntelliSense does not help? For the case of MSBuild, usually there will be a window of all the possible variables, along with their resolved values.
As an aside, is there a way to define variables at a per-user leve, so files like launch.vs.json can take take it in? For example, defining targetAddr=192.168.1.2, and then use ${targetAddr} in the json file. One method is to define the variable in the json file itself, but I wish to commit the file as a "default" for team members, and let team members inject values through variables, without making the json file "dirty".

Android Studio Method doc for jar file

I created a jar file using android studio exposing some methods and using the jar file in another android project.
For accessing any method when I type the first letter of method, the Android Studio intelliSense shows me different option of method names along with the parameters expected by these methods.
The parameters names that appear are (String s1, String s2) and so on instead of original parameters like (String Name, String Address) which does not gives a proper meaning.
What can I do to change this behavior?

Finding the default project settings file

I'm trying to write a plugin for 3ds max, I went through the entire sdk installation process to the letter as described in the help files.
The problem I'm facing though is intellisence complaining about an invalid macro definition
"IntelliSense: command-line error: invalid macro definition:_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT =1"
I found the definition in project settigs -> c/c++ -> preprocessor definitions as inherited from parent or project default.
I tried disabling the inherited definitions and re-entered them, this time without the space between the name and the = and all works fine so I'm guessing its a typo on their part?
Anyway, I want to change the default project or whatever to not repeat it every time i start a new project. The project is created with a wizard which required me to copy over some files to appear and after which I had to enter the sdk path.
The files I copied are plain text with some fancy extensions and not much in them so I'm guessing the defaults are described in the sdk directory.. somewhere. Does anybody know what kind of a file I'm looking for?
EDIT: I found a file called root.vcxproj_template and it has a section for preprocessor definitions but all it contains is
<PreprocessorDefinitions>_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
and no mention of the broken one
EDIT2: in another part of the file there was a path to a property sheet (maxsdk\ProjectSettings\propertySheets\3dsmax.common.tools.settings) which included the faulty definition. I fixed it an no more complaints from VS.
_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT = 1 means that compiler should replace all old C run-time routines such as sprintf, strcpy, strtok with new versions such as strprintf_s, strcpy_s, strtok_s and similar. It goes in pair with following definition _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES = 1.
More you can find here: (MSDN) https://msdn.microsoft.com/en-us/library/ms175759.aspx. However I tried to use this but without success. It says that you can use this only for statically allocated buffers like char buffer[32], but compilers was still complaining bout unsecure strcpy.

Resources