Jetpack Compose preview stopped working in Arctic Fox with Patch 1 - android-studio

With the first patch for AS Arctic Fox Jetpack Compose previews stopped working.
I'm getting this error for all previews - even older ones, which worked fine a while back:
android.content.res.Resources$NotFoundException: Could not resolve resource value: [some hex value]
Are here any quick fixes for this? Clearing caches and the usual stuff did not work.
EDIT:
Looks like the problem is not always present. Some preview started working, while other are still failing.
EDIT 2:
This is happening in dynamic feature modules, when there's a need for resources from the main module or painterResource() is being used (even is resource from the same module is to be displayed).

Same problem here with dynamic-modules project.
Inspired by above answer, I've made another temporary workaround while waiting for Compose team to fix this.
import androidx.compose.ui.res.stringResource as originalStringResource
#Composable
#ReadOnlyComposable
fun stringResourceSafe(#StringRes id: Int): String =
if (BuildConfig.DEBUG) {
val resources = LocalContext.current.resources
try {
resources.getString(id)
} catch (e: Resources.NotFoundException) {
"missing res."
}
} else {
originalStringResource(id)
}

This got fixed in AS Bumblebee, patch 2.

As a temporary hack workaround I did this to get past the error and preview the UI elements.
//import androidx.compose.ui.res.stringResource
fun stringResource(id: Int): String {
when (id) {
R.string.res_id -> return "Foo"
...
}
return "missing res_id"
}

Related

How to create Mapbox Marker Onclick Eventlistener Android Studio?

Hello Stackoverflow community,
I am trying to develop an Android application with Mapbox.
I followed this guide to create markers on the map.
https://docs.mapbox.com/android/maps/examples/default-point-annotation/
Thus my code is the following:
public fun createMarker(id: String, lon: Double, lat: Double) {
// Create an instance of the Annotation API and get the PointAnnotationManager.
var marker: PointAnnotation? = bitmapFromDrawableRes(
drawercontext,
R.drawable.red_marker
)?.let {
val annotationApi = binding.mapBoxView.mapView?.annotations
val pointAnnotationManager =
annotationApi?.createPointAnnotationManager(binding.mapBoxView.mapView!!)
// Set options for the resulting symbol layer.
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
// Define a geographic coordinate.
.withPoint(Point.fromLngLat(lon, lat))
// Specify the bitmap you assigned to the point annotation
// The bitmap will be added to map style automatically.
.withIconImage(it)
// Add the resulting pointAnnotation to the map.
pointAnnotationManager?.create(pointAnnotationOptions)
}
}
Unfortunately, I can not find any solution to add a click listener to markers (to show extra information outside of the map). In my opinion, this should be an important event, so I don't get why there is so little support. I want to replicate something like this:
https://bl.ocks.org/chriswhong/8977c0d4e869e9eaf06b4e9fda80f3ab
But in Android Studio with Kotlin.
One workaround I have seen is to add a click listener to the map and from there determine the marker with the closest coordinates, but I think that would not be as nice of a solution. Do you know any solutions or workarounds to my problem?
Thanks for the help in advance!
try this:
pointAnnotationManager.apply {
addClickListener(
OnPointAnnotationClickListener {
Toast.makeText(this#MainActivity, "id: ${it.id}", Toast.LENGTH_LONG).show()
false
}
)
}

Preferences library is causing E/libc & E/Pref errors

I'm building a weather app using MVVM and retrofit and i recently added a PreferencesFragmentCompat subclass to implement some user settings using the preferences lib. After doing so, my app won't run and i keep getting these few lines of errors :
2020-04-08 00:54:12.346 18079-18079/? E/de.flogaweathe: Unknown bits set in runtime_flags: 0x8000
2020-04-08 00:54:12.410 18079-18079/com.nesoinode.flogaweather E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list com.nesoinode.flogaweather
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list oat
2020-04-08 00:54:12.422 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
I've got no idea what these are and i can't find any specific answers on stack or google.There are no indications on what is causing the error so i can't figure out if i'm doing something wrong or if it is a library issue. Any ideas?
Here's the SettingsFragment where i'm adding the preferences from an xml resource file :
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.settings_prefs)
}
}
And here's how i'm reading some values from the sharedPrefs:
class UnitProviderImpl(context: Context) : UnitProvider {
private val appContext = context.applicationContext
private val preferences:SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(appContext)
override fun getUnitSystem(): String {
val selectedUnitSystemName = preferences.getString(UNIT_SYSTEM_KEY,
UnitSystem.SI.name.toLowerCase(Locale.ROOT))
return selectedUnitSystemName!!
}
}
I managed to figure out a solution to the issue after doing some more research. Firstly, i commented out all the code related to the preferences library (and the lib itself) and run the app again. The run was successful without any errors so that narrowed it down to the androidx.preference:preference-ktx:1.1.0 library itself since my code was reviewed and couldn't find any issues with it. Looking through the preference docs i figured i could try out a beta or alpha version that may have fixed this issue. And lo and behold, after using the androidx.preference:preference-ktx:1.1.0-beta01 beta version and uncommenting the relative code, everything worked once again.

Missing class: com.fasterxml.jackson.core.type.TypeReference. R8:Warning

After I updated Android Studio to 3.5, I am facing below warning whenever I build my Project.
Missing class: com.fasterxml.jackson.core.type.TypeReference
My project is using AndroidX. Here is the gist for my build.gradle(app)
https://gist.github.com/Arkar009/4ae5a05ff3435636bc605fee1fbdb050 . Can anyone know why this error occurs or alternative ideas to solve this error? Thanks in advances.
If you're super sure you will remember this line if you include Jackson later in your project, this does the trick (add it in your project's proguard-project.[txt|pro] file):
-dontwarn com.fasterxml.jackson.core.type.TypeReference
That class gets included somehow in the missing classes Set in R8 (I didn't go that far in R8's code), but you can skip the warning if you get that class in the list of patterns for "Don't Warn" rules (see com/android/tools/r8/R8.java):
List<ProguardConfigurationRule> synthesizedProguardRules = new ArrayList<>();
timing.begin("Strip unused code");
Set<DexType> classesToRetainInnerClassAttributeFor = null;
try {
Set<DexType> missingClasses = appView.appInfo().getMissingClasses();
missingClasses = filterMissingClasses(
missingClasses, options.getProguardConfiguration().getDontWarnPatterns());
if (!missingClasses.isEmpty()) {
missingClasses.forEach(
clazz -> {
options.reporter.warning(
new StringDiagnostic("Missing class: " + clazz.toSourceString()));
});
TBH, I was also bugged enough by this warning to get into R8, hope it helps!

Testcafe: using Test Controler in boundTestRun not working

I'm trying to work with shadow roots in my Testcafe project. It's a little bit complicated to deal with it. I create a custom function that behaves the same as Selector().find() but I struggle with this error :
The "boundTestRun" option value is expected to be a test controller.
when I'm doing as documented here :
import { Selector, t } from 'testcafe'
getInShadowRoot = Selector(
// More code here
)
const boundedGetInShadowRoot = this.getInShadowRoot.with({ boundTestRun: t })
I create a gist to illustrate my problem: https://gist.github.com/HugoDel/a600f3e120674e3f255884f3dc84fee3
Thanks for your help!
Edit:
I finally get rid of it since I don't need to add .with({ boundTestRun: t }) to make it work.

Why do I get a "connot be applied to 'Closure'" Warning in my gradle script?

I have a hard time figuring out, why IntelliJ warns me about this part in my build.gradle file:
apply plugin: 'distribution'
(...)
distributions {
main {
baseName = 'someName'
contents {
from { 'src/readme' }
}
}
}
shot:
I took it straight from the gradle user guide and the build seems to work ok. So, is this a false positive or should I take this serious? If so, what's the problem here and how would one check the API / code to find the expected types and so on?
it is a false positive, but if you want to make it disappear use the following
apply plugin: 'distribution'
distributions.create('someNameButMain', {
baseName = 'someName'
contents {
from { 'src/readme' }
}
})

Resources