I see a crash whenever my android app initializes a kotlin class. From the stack trace, I see it's from the static initializer of the BuiltInsLoader.Companion object:
kotlin.collections.CollectionsKt___CollectionsKt.first
(CollectionsKt___CollectionsKt.java:166)
kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader$Companion.
(BuiltInsLoader.java:38)
kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader.
(BuiltInsLoader.java)
kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns.createBuiltInsModule
(KotlinBuiltIns.java:150)
kotlin.reflect.jvm.internal.impl.platform.JvmBuiltIns.
(JvmBuiltIns.java:56)
kotlin.reflect.jvm.internal.impl.platform.JvmBuiltIns.
(JvmBuiltIns.java:31)
kotlin.reflect.jvm.internal.components.RuntimeModuleData$Companion.create
(RuntimeModuleData.java:54)
kotlin.reflect.jvm.internal.KDeclarationContainerImpl$Data$moduleData$2.invoke
(KDeclarationContainerImpl.java:35)
kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke
(ReflectProperties.java:93)
kotlin.reflect.jvm.internal.ReflectProperties$Val.getModuleData
(ReflectProperties.java:32)
kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor$2.invoke
(KClassImpl.java:46)
kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke
(ReflectProperties.java:93)
kotlin.reflect.jvm.internal.ReflectProperties$Val.getDescriptor
(ReflectProperties.java:32)
kotlin.reflect.jvm.internal.KClassImpl.getDescriptor
(KClassImpl.java:172)
kotlin.reflect.jvm.internal.KClassImpl.getConstructorDescriptors
(KClassImpl.java:186)
kotlin.reflect.jvm.internal.KClassImpl$Data$constructors$2.invoke
(KClassImpl.java:90)
kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke
(ReflectProperties.java:93)
kotlin.reflect.jvm.internal.ReflectProperties$Val.create
(ReflectProperties.java:32)
The decompiled static block looks like this:
BuiltInsLoader.Companion var0 = new BuiltInsLoader.Companion();
$$INSTANCE = var0;
ServiceLoader var10000 = ServiceLoader.load(BuiltInsLoader.class, BuiltInsLoader.class.getClassLoader());
Intrinsics.checkExpressionValueIsNotNull(var10000, "ServiceLoader.load(Built…::class.java.classLoader)");
Object var1 = CollectionsKt.first((Iterable)var10000);
Has anyone else experienced this crash? If so, how do you fix this initialization error?
This exception can occur if a certain resource file, needed for kotlin-reflect to work correctly, is missing at runtime. The file is located at META-INF/services/kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader. Please verify that no tools remove it during the build and it's present in the final application.
The relevant issue in the Kotlin tracker: https://youtrack.jetbrains.com/issue/KT-20575
Maybe:
packagingOptions {
exclude 'META-INF/services/kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader'
}
Might help
Related
So I have been using the YouTube API successfully for the past few months in Android Studio. I went to update my app and as of today the app keeps crashing when it is trying to initialize the YouTube builder. Has anyone else experienced this problem?
mYoutubeDataApi = new YouTube.Builder(mTransport, mJsonFactory, null)
.setApplicationName(getResources().getString(R.string.app_name))
.build();
The app crashes with the following output:
2019-12-09 01:38:06.443 17937-17937/ E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.google.api.services.youtube.YouTube.<clinit>(YouTube.java:44)
at com.google.api.services.youtube.YouTube$Builder.build(YouTube.java:16644)
Line 44 in the YouTube.java file is:
public class YouTube extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient {
// Note: Leave this static initializer at the top of the file.
static {
com.google.api.client.util.Preconditions.checkState(
com.google.api.client.googleapis.GoogleUtils.MAJOR_VERSION == 1 &&
com.google.api.client.googleapis.GoogleUtils.MINOR_VERSION >= 15,
"You are currently running with version %s of google-api-client. " +
"You need at least version 1.15 of google-api-client to run version " +
"1.30.1 of the YouTube Data API library.", com.google.api.client.googleapis.GoogleUtils.VERSION);
}
In 1.30.6, they added this: https://github.com/googleapis/google-api-java-client/pull/1419
To fix, edit your build.gradle back down to 1.30.5
dependencies {
implementation ('com.google.api-client:google-api-client:1.30.5')
implementation ('com.google.api-client:google-api-client-android:1.30.5')
}
If there's a better solution, I'd like to hear it!
To further explain why that change in 1.30.6 causes the crash, here's some more info.
Specifically, the issue is coming from this file: https://github.com/googleapis/google-api-java-client/blob/master/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java
Caused by: java.lang.IllegalStateException: No successful match so far
at java.util.regex.Matcher.ensureMatch(Matcher.java:1116)
at java.util.regex.Matcher.group(Matcher.java:382)
at com.google.api.client.googleapis.GoogleUtils.<clinit>(Unknown Source:26)
Here is the relevant code
public static final String VERSION = getVersion();
static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(-SNAPSHOT)?");
static {
Matcher versionMatcher = VERSION_PATTERN.matcher(VERSION);
versionMatcher.find();
MAJOR_VERSION = Integer.parseInt(versionMatcher.group(1));
MINOR_VERSION = Integer.parseInt(versionMatcher.group(2));
BUGFIX_VERSION = Integer.parseInt(versionMatcher.group(3));
}
private static String getVersion() {
String version = GoogleUtils.class.getPackage().getImplementationVersion();
// in a non-packaged environment (local), there's no implementation version to read
if (version == null) {
// fall back to reading from a properties file - note this value is expected to be cached
try (InputStream inputStream =
GoogleUtils.class.getResourceAsStream("google-api-client.properties")) {
if (inputStream != null) {
Properties properties = new Properties();
properties.load(inputStream);
version = properties.getProperty("google-api-client.version");
}
} catch (IOException e) {
// ignore
}
}
return version;
}
Presumably, getVersion is returning null, although I can't say why. Seeing as how this recently happened for me 2-3 days ago also, something we updated must be conflicting.
This bug is fixed in com.google.api-client:google-api-client:1.30.7. Upgrading to that version or later will fix it.
In the latest version, they have added the library proguard file, which keeps the the GoogleUtils.java and hence keeps the google-api-client.properties which gets generated in build time.
Initially they used to update the string literal for version name for each release hence that time parsing of version name done in GoogleUtils.java was crash free.
But later on they shifted to parsing the version from google-api-client.properties at GoogleUtils.java which started giving error as proguard started removing the generated google-api-client.properties file.
Later on after release, 1.30.9 at this commit id the started using the embedded proguard rule to keep the GoogleUtils.java file
They actually fixed the issue at release, 1.30.8 at the commit, 1.30.9 release just does the same fix in more android recommended way.
Although the final adopted version uses GoogleUtils.class.getResourceAsStream("google-api-client.properties") which is Java api and returns the InputStream to read the google-api-client.properties file. Since these stream may not work perfectly in some devices they still crash but with lesser frequency(as we still see the crashes with the fixed present in the release 1.30.9).
Created an issue to track this
I have been trying a ( i hope) simple bit of Android hyperloop code directly within a titanium project (using SDK 7.0.1.GA and hyperloop 3).
var sysProp = require('android.os.SystemProperties');
var serialNumber = sysProp.get("sys.serialnumber", "none");
But when the app is run it reports
Requested module not found:android.os.SystemProperties
I think this maybe due to the fact that when compiling the app (using the cli) it reports
hyperloop:generateSources: Skipping Hyperloop wrapper generation, no usage found ...
I have similar code in a jar and if I use this then it does work, so I am wondering why the hyperloop generation is not being triggered, as I assume that is the issue.
Sorry should have explained better.
This is the jar source that I use, the extraction of the serial number was just an example (I need access to other info manufacturer specific data as well), I wanted to see if I could replicate the JAR functionality using just hyperloop rather that including the JAR file. Guess if it's not broke don't fix it, but was curious to see if it could be done.
So with the feedback from #miga and a bit of trial and error, I have come up with a solution that works really well and will do the method reflection that is required. My new Hyperloop function is
function getData(data){
var result = false;
var Class = require("java.lang.Class");
var String = require("java.lang.String");
var c = Class.forName("android.os.SystemProperties");
var get = c.getMethod("get", String.class, String.class);
result = get.invoke(c, data, "Error");
return result;
}
Where data is a string of the system property I want.
I am using it to extract and match a serial number from a Samsung device that is a System Property call "ril.serialnumber" or "sys.serialnumber". Now I can use the above function to do what I was using the JAR file for. Just thought I'd share in case anyone else needed something similar.
It is because android.os.SystemProperties is not class you can import. Check the android documentation at https://developer.android.com/reference/android/os/package-summary.html
You could use
var build = require('android.os.Build');
console.log(build.SERIAL);
to access the serial number.
i tried setting up acra for my android project today, but it didnt work. I followed the instructions, importet the acra lib in gradle (compile 'ch.acra:acra:4.7.0')
Then i added this:
#ReportsCrashes(formKey = "", mailTo = "mail#adress.com", mode = ReportingInteractionMode.NOTIFICATION)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ACRA.init(this.getApplication());
I get the error Cannot resolve method 'formKey', but when deleting formkey from parameters, i get #ReportsCrashes not applicable to method
I also tried
#ReportsCrashes(formUri = "http://www.yourselectedbackend.com/reportpath")
and
#ReportsCrashes(formKey = "", formUri = "http://www.yourselectedbackend.com/reportpath")
and get the same errors. Anyone knows the issue/solution? The wiki at https://github.com/ACRA/acra/wiki seems outdated and there is no issue about this.
formKey has been removed for some time. I don't know where you saw instructions to use it, but they should no longer exist too. Use formUri.
You are getting #ReportsCrashes not applicable to method because you have annotated your onCreate method. You need to annotate your Application class
In our android app, we use Jackson Annotations in our models:
#JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "templateType", visible = true, defaultImpl = Default.class)
#JsonSubTypes({
#Type(value = Subclass1.class, name = "tType1")
We parse the json response using object mapper where klass is the class of the object file which we wish to parse to:
getObjectMapper().readValue(json, klass);
On rare scenarios on Android Lollipop devices, we get
java.lang.IncompatibleClassChangeError: Couldn't find com.fasterxml.jackson.annotation.JsonSubTypes$Type.value.
Full stack trace:
com.fasterxml.jackson.annotation.JsonSubTypes$Type.value
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:659)
at java.lang.Class.getDeclaredAnnotations(Class.java:891)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass.resolveClassAnnotations(AnnotatedClass.java:300)
at com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector.isIgnorableType(JacksonAnnotationIntrospector.java:103)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.isIgnorableType(BeanDeserializerFactory.java:844)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:401)
at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:305)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:151)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.findDeserializer(StdDeserializer.java:634)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:438)
at com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:173)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:99)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:106)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
This is a confirmed bug on some Samsung devices. Unfortunately there is no fix yet, but this Android Bug Tracker thread will probably come up with a fix (if possible) soon:
https://code.google.com/p/android/issues/detail?id=172339
I'm a flex developer and have a small problem.
I use XMLApllicationContext to load an XML file.
I load my context and then add the config location to it.
In this files I take care of creating an URL to connect to.So I made an eventlistner for my XMLApplicationContext with Event.COMPLETE so I know when he's done and he can connect.
No I'm a little bit dummytesting and if the user has given a wrong host and port the URL will not exist. So there will never be an Event.COMPLETE action.
For that I would love to know how I can solve this.
Now I have this code:
public function execute():*
{
m_context = new XMLApplicationContext("application-context.xml");
m_context.addConfigLocation("application-context-services.xml");
m_context.addEventListener(Event.COMPLETE, onComplete);
m_context.addEventListener(......);//need to know what has to come between the brackets
m_context.load();
ServiceLocator.getInstance().context = m_context;
}
I allready tried some things but haven't found a solution yet.
Thank you in advance.
Kind regards,
Thibault Heylen
Did you try the IOErrorEvent?
If that doesn't work for you, you could try creating a file reference and check if it exists ...
var f:File = new File("application-context.xml");
if (f.exists) {
//...
}
Im not quite sure, but if this is a local file you maybe have to add "app:/path/to/file/" in front of your url/file name