Android Studio DAO Syntax Highlighting, DB Inspector and Language Injection - android-studio

Since my last build upgrade, the syntax highlighting in my DAOs is not working anymore.
My expectation (and experience) is, that there is syntax highlighting in the queries and once the database inspector is running, there is also a button on the left side, which executes the SQL statement on the running database.
I don't know, why this happened. The only thing I did, was run recommended upgrades for my build gradles. Also, reverting these changes did not improve the situation.
At least in regards to syntax highlighting I found a solution:
However, that still does not resolve the problem of "Quick running" the sql statement in the database inspector.
Also to note here, I tried already this: How to highlight SQL syntax of Room Dao in Android Studio, which did not work. In my case, there is no listing for "Android Room SQL", but only "Room SQL".
Any ideas?

Auto highlighting still doesn't work with:
Android Studio Electric Eel | 2022.1.1
Build #AI-221.6008.13.2211.9477386, built on January 11, 2023
and
room: 2.5.0
in kotlin #Dao class.
So, as said here, you should:
Go to Settings > Editor > Language Injections
Add a new injection of type "Generic Kotlin"
Choose "RoomSQL" as the ID for the injection.
Add the following for the "Places Patterns":
+ kotlinParameter().ofFunction(0, kotlinFunction().withName("Query").definedInClass("androidx.room.Query"))
+ kotlinParameter().ofFunction(0, kotlinFunction().withName("DatabaseView").definedInClass("androidx.room.DatabaseView"))
And injection works fine!

I have asked same question at issuetracker.google.com: https://issuetracker.google.com/issues/234612964
An intermediate solution is here:
https://issuetracker.google.com/issues/234612964#comment6
Please check that link out, there is a work-around there which works with '2.5.0-alpha03' at least. Haven't tested it with '2.5.0-alpha02'.
There will be a fix for it in Android Studio soon (september/october 2022)

Don't use alpha version of room in gradle. Use stable version only.
I was using alpha version of room:
implementation 'androidx.room:room-ktx:2.5.0-alpha02'
implementation 'androidx.room:room-common:2.5.0-alpha02'
kapt 'androidx.room:room-compiler:2.5.0-alpha02'
androidTestImplementation 'androidx.room:room-testing:2.5.0-alpha02'
When I migrated to stable version it resolved the issue.
implementation 'androidx.room:room-ktx:2.4.3'
implementation 'androidx.room:room-common:2.4.3'
kapt 'androidx.room:room-compiler:2.4.3'
androidTestImplementation 'androidx.room:room-testing:2.4.3'

Related

Why is my android studio kotlin plugin version in different format than my co-workers?

I stumbled into an issue where all my unit test classes fail to run, providing the following error:
java.lang.IllegalStateException: Failed to transform class with name <my class name>. Reason: toPrettyPrint (Ljava/lang/String;)Ljava/lang/String; in <my class name>: inconsistent stack height -1
One user commented on the following github thread for powermock, that the same error first happened to them after updating their kotlin plugin:
https://github.com/powermock/powermock/issues/779
After reading this, I have checked with my colleagues to see maybe they have a different kotlin version, and saw that their kotlin plugin version is
203.1.6.0-release-798-AS7717.8, whereas mine is 1.4.32-release-Studio4.1-1.
What I find peculiar abbout this, is that these versions dont follow the same conventions, they look more like two completely different sofware. Is there any way for me to get the same version for my kotlin plugin ?
Any help or clarification is much appreciated, thanks!
They probably just changed the naming scheme for the plugin. Looks like you have one that is about one and a half years out of date.
Anyway, go to File -> Settings -> Languages & Frameworks -> Kotlin and click the Install button.

error: Cannot figure out how to save this field into database. You can consider adding a type converter for it. - obs in java.util.Observable

I just upgraded my android studio to Artic fox. And all of sudden I am facing an issue saying "error: Cannot figure out how to save this field into database. You can consider adding a type converter for it. - obs in java.util.Observable". It was working fine for the previous android version. Can any one help me please. I am stuck!! I tried every thing but did not work out.
Thanks in advance.
dependencies are as follows:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10"
implementation 'androidx.room:room-runtime:2.2.5'
kapt 'androidx.room:room-compiler:2.2.5'
androidTestImplementation 'androidx.room:room-testing:2.2.5'

Updated android studio and got fail with Gstreamer build

Updated to Android Studio 3.0.0 with new android gradle plugin.
While buildin project got message:
What went wrong:
Execution failed for task `':app:externalNativeBuildDebug'`.
Expected output file at `gst-build-arm64-v8a/libgstreamer_android.so` for target `gstreamer_android` but there was none
but libgstreamer_android.so library file is already there. For native code I use ndk-build. Does anyone have this issue?
Add to build.gradle file of our android module field targets.
android {
defaultConfig {
externalNativeBuild {
ndkBuild {
targets "name_of_native_module_in_android_mk_file"
}
...
}
Don't add gstreamer_android.
UPDATE: Valery's answer works!
Obsolete answer:
That's not the perfect fix, it's just temporary until I have time to take a deep look into the problem. Downgrade your gradle plugin:
File -> Project Structure
Click at "Project"
At "Gradle version" field put:
3.3
At "Android Plugin Version" field put:
2.3.3
Hit "OK"
Accept the messages, sync the project, etc... Android Studio may prompt a windown asking for update gradle plugin again, just don't accept it for now...
I guess the update on gradle changed the way the builds are made, maybe something on Android.mk will have to change or some other parameter on build.grade...
edit: I found some clue at: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
API changes Android plugin 3.0.0 introduces API changes that removes
certain functionalities and may break your existing builds. Later
versions of the plugin may introduce new public APIs that replace
broken functionalities.
Modifying variant outputs at build time may not work Using the Variant
API to manipulate variant outputs is broken with the new plugin. It
still works for simple tasks, such as changing the APK name during
build time, as shown below:...
So, I guess we should keep using the temporary fix (not updated version of gradle)...

MissingTranslation Errors after Upgrading to Gradle 3.3

Since upgrading to Gradle 3.3 I'm having trouble building my code due to missing-translation errors:
Error: xxx is not translated in "af" (Afrikaans), "am" (Amharic), "ar" (Arabic), "az" (Azerbaijani), "az-AZ" (Azerbaijani: Azerbaijan), "be" (Belarusian), "bg" (Bulgarian), "ca" (Catalan), [...], "zh-TW" (Chinese: Taiwan), "zu" (Zulu) [MissingTranslation]
The majority of the reported languages are those supported by a 3rd-party module included in my project, and it now seems to define the supported languages for the entire project, giving me this kind of error for all strings that are not translated into above languages. Before upgrading to Gradle 3.3 this was not causing any problems.
I considered the following solutions:
Remove surplus translations from other modules. I want to avoid that because those modules are external and needlessly altering them would really hurt maintainability of my project.
Disable the "incomplete translation" Lint inspection - the most common suggestion for similar questions on SO. This is sub-optimal because I want to be made aware of translations that are missing in my code (working so far). Besides that, disabling the check does not get rid of the error.
Define the supported configurations in build.gradle as described in this answer. I like this option (specifying languages instead of relying on translations available in the modules), but it also does something strange: I'm getting missing-translation errors for strings that are marked translatable = false.
For now, I'm downgrading again to the previous Gradle version. But what is the best apporach for fixing these build errors?
Hoping that there might have been corrections since I posted this question a few months ago, I checked the situation.
It seems that the issues were introduced with the Gradle plugin 2.3.0 and not Gradle 3.3 itself as I suggested in the question. Downgrading the plugin avoids the errors but can hardly be a long-term solution.
I found that option 3 in the question is the best way to handle it: add this to the app's build.gradle:
android {
defaultConfig {
...
resConfigs "en", "fr"
}
}
This is described in Googles documentation and, as mentioned, also in this answer. It removes all unnecessary resources - and the warnings/errors along with them.
Quoting the documentation:
The Gradle resource shrinker removes only resources that are not referenced by your app code, which means it will not remove alternative resources for different device configurations. If necessary, you can use the Android Gradle plugin's resConfigs property to remove alternative resource files that your app does not need.
For example, if you are using a library that includes language
resources (such as AppCompat or Google Play Services), then your APK
includes all translated language strings for the messages in those
libraries whether the rest of your app is translated to the same
languages or not. If you'd like to keep only the languages that your
app officially supports, you can specify those languages using the
resConfig property. Any resources for languages not specified are
removed.
The "false positives" (missing translation error for a non-translatable string) I got were for strings that were defined in more than one module. Renaming the strings or providing translations for them solved the problem. This, too, seems to be introduced with Gradle plugin 2.3.0.
In build.gradle add below code
lintOptions {
disable 'MissingTranslation'
}

Multiple #:build macros

To give a class multiple build macros, I previously stacked #:build() tags. I updated to dev haxe, and now it's only recognizing the last tag. Was the syntax for this changed recently, or is this a bug?
#:build(Macros.thisMacroDoesntRunAtAll())
#:build(Macros.thisMacroWorksNormally())
class Test {
I don't remember what dev version of haxe I used to be on, but it was after the 3.2.0 master release.
It's a haxe bug, and it seems like Simon is aware.
Oh well.

Resources