Cannot initialize Crashlytics NDK - crashlytics

I got a problem in initalizing Crashlytics for Android. The Java part works correctly but i cannot make NDK part to work because crashlytics_init() return a null value;
My project/build.gradle
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'io.fabric.tools:gradle:1.24.4'
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url 'https://maven.fabric.io/public'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle containing
compileSdkVersion 26
android {
defaultConfig {
...
minSdkVersion 19
targetSdkVersion 22
...
}
...
}
crashlytics {
enableNdk true
manifestPath 'C:\\full\\path\\to\\manifest\\AndroidManifest.xml'
}
dependencies {
implementation 'com.google.firebase:firebase-crash:11.6.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6#aar') {
transitive = true;
}
compile 'com.google.firebase:firebase-core:11.6.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'org.apache.commons:commons-compress:1.12'
compile 'org.tukaani:xz:1.5'
}
main activity code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
jniCrashlyticsInit();
...
}
and the native content of jniCrashlyticsInit()
void Java_com_my_app_MainActivity_jniCrashlyticsInit(JNIEnv *env,
jobject thiz)
{
crashlytics = crashlytics_init();
if (crashlytics == NULL)
log("CRASHLYTICS NULL");
else
log("CRASHLYTICS NON NULL");
}
As you imagine, "CRASHLYTICS NULL" is logged and it cannot initialize all the stuff.
I've put logs also inside crashlytics.h and it happens to fail on this line (returning a null value)
__crashlytics_unspecified_t* ctx = ((__crashlytics_initialize_t) sym_ini)();
Since i got no further infos, i really don't know how to proceed.
Ideas?
Some info more:
I use Android studio 3.0.0, and the NDK libraries are compiled manually with the following command
/cygdrive/c/Android/ndk-r15c/ndk-build.cmd NDK_DEBUG=0 APP_BUILD_SCRIPT=./Android.mk NDK_PROJECT_PATH=. APP_PLATFORM=android-19
**** Update November 20th ****
As suggested by Todd Burner, I switched from "compile" to "implementation" on build.gradle from
compile('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6#aar') {
transitive = true;
}
to
implementation('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
implementation('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6#aar') {
transitive = true;
}
then i ran
./gradlew assemble --refresh-dependencies
Unfortunally, crashlytics_init() still returns NULL

I struggled days with this same issue. In my case I would blame partly the not-so-very-thorough documentation in the Fabric website and partly the lack of my reading comprehension.
I cannot be sure if you experience just the same thing, but my problem was that I tried to load Crashlytics NDK twice.
If you do the initialization from java like this:
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
the native Crashlytics is automatically loaded and you don't need to initialize Crashlytics from C++. If you step into the decompiled Crashlytics .class files starting from CrashlyticsNdk.class you can see that JniNativeApi.class already calls System.loadLibrary("crashlytics").
In fact, if you still try to initialize Crashlytics from native side after that, the line
__crashlytics_unspecified_t* ctx = ((__crashlytics_initialize_t) sym_ini)();
will return NULL because the library has been already loaded.
What confused me is that the Official Fabric documentation doesn't say with bright red flashing letters that if you call new CrashlyticsNdk() from Java, you shouldn't try to load native Crashlytics from C++. To be fair, the documentation does say the following: In the process of initialization via Fabric.with(), the NDK Kit uses System.loadLibrary to load libcrashlytics. But it's a single line right before the Native API explanation starts and is easily overlooked.

Related

How can I find the main class of my app when selecting it to create a JAR ? Kotlin

I want to make a JAR to test and deploy my app but it doesn't work, locally it can't find the main attribute in the manifest file, and in the deployement it starts but i have this error :
java.lang.noclassdeffounderror: kotlinx/coroutines/slf4j/mdccontex
W
hen I do it locally using the artifact Jar I can't find the MainClass of my app, it recommands me all sorts of other modules.
I tried modying my gradle, the manifest, the configuration but really nothing works it's depressing, it looks so easy on some youtube videos but it just doesn't work
what I do to make the JAR
The classes i have access to when i try to select them
Here is my Gradle
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.5.10"
application
kotlin("plugin.serialization") version "1.6.10"
}
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven(url = "https://jitpack.io")
}
val ktor_version: String by project
dependencies {
// Fix HTML issue on some responses
implementation("org.apache.commons:commons-text:1.10.0")
// Ktor dependencies
implementation("io.ktor:ktor-client-auth:$ktor_version")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version")
implementation("io.ktor:ktor-client-resources:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")
// Logging dependencies
implementation("ch.qos.logback:logback-classic:1.4.0")
implementation(kotlin("stdlib-jdk8"))
// Database
implementation ("mysql:mysql-connector-java:8.0.30")
implementation ("org.ktorm:ktorm-core:3.5.0")
implementation ("org.ktorm:ktorm-support-mysql:3.5.0")
}
application {
mainClass.set("MainKt")
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
tasks {
jar {
manifest {
attributes["Main-Class"] = application.mainClass
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations.compileClasspath.get().forEach {
from(if (it.isDirectory) it else zipTree(it))
}
}
compileKotlin{
kotlinOptions.jvmTarget = "1.8"
}
}
Thanks in advance
My project had a lot of issues and inconsistency so I started a new one and copied all the files / packages, spent an hour redoing all the imports and plugins that my code actually needed to run and it finally worked, the same comments don't work on the previous project

Google Service download failure in gradle

Followed the instructions specified in firebase cloud platform. Getting this issue while running the gradle build.
Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.android.gms:google-services:4.3.3.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/gms/google-services/4.3.3/google-services-4.3.3.pom
- https://jcenter.bintray.com/com/android/gms/google-services/4.3.3/google-services-4.3.3.pom
Required by:
project :
build.gradle , with the artifact added.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 16
compileSdkVersion = 29
targetSdkVersion = 29
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.3")
classpath("com.android.gms:google-services:4.3.3")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
Any inputs to the issue will help, checked firewall and proxy issues already.
There are two build.gradle files in an Android Project. One is for app-level and another one is for your project root-level.
In order to setup Firebase correctly, You have to write like following in your root-level (project-level) Gradle file (build.gradle):
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
// ...
// Add the following line:
classpath 'com.google.gms:google-services:4.3.3' // Google Services plugin
}
}
allprojects {
// ...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
// ...
}
}
In your module (app-level) Gradle file (usually app/build.gradle), apply the Google Services Gradle plugin like below snippet:
apply plugin: 'com.android.application'
// Add the following line:
apply plugin: 'com.google.gms.google-services' // Google Services plugin
android {
// ...
}
You are doing everything but in the app-level file. Try Fixing it and tell whether it worked or not.

How to build kotlinx.coroutines in Kotlin/Native (test version 0.23.4-native-1)

This question is a continuation of this thread:
https://github.com/Kotlin/kotlinx.coroutines/issues/246#issuecomment-407023156
I am trying to use org.jetbrains.kotlinx:kotlinx-coroutines-core-native:0.23.4-native-1 in a Kotlin/Native project targeting iOS.
build.gradle:
buildscript {
repositories {
mavenCentral()
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.8'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
}
}
apply plugin: 'kotlin-platform-native'
repositories {
jcenter()
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
sourceSets {
main {
component {
target 'ios_arm32', 'ios_arm64', 'ios_x64'
outputKinds = [KLIBRARY]
}
}
}
dependencies {
expectedBy project(':common')
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:0.23.4-native-1"
}
The kotlinx:kotlinx-coroutines-core-native dependency doesn't seem to work, as the produces build errors like:
error: unresolved reference: coroutines
import kotlinx.coroutines.experimental.*
^
If I manually include the artifact dependencies such as org.jetbrains.kotlinx:kotlinx-coroutines-core-native_release_ios_x64:0.10.3-native, then I get a complier exception:
exception: java.lang.IllegalStateException: Could not find "atomicfu-native"
This error persists, even if I also add org.jetbrains.kotlinx:atomicfu-native:0.10.3-native dependency.
Here is a list of things to check for (I have been through this, and finally made it work) :
Enable Gradle metadata. It's required to retrieve the coroutines dependencies. To do so, add this line in your "settings.gradle" file, after all the "include" instructions :
enableFeaturePreview('GRADLE_METADATA')
use gradle 4.7 (newer version are incompatible with the meta data of the current coroutines library, they require something with 0.4 version and the current published one uses 0.3)
In the iOS module :
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:0.23.4-native-1"
In your common module :
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4"
If you have a js module, it may fail due to the gradle metadata feature. You can fix it by adding this before each of your "repositories" blocks (https://github.com/srs/gradle-node-plugin/issues/301)
repositories.whenObjectAdded {
if (it instanceof IvyArtifactRepository) {
metadataSources {
artifact()
}
}
}
Hope this will be enough !

librashlitics does not exists in build

I'm trying to integrate Fabric Crashlitics with native code. I had crashes in native code but there are no any records about them in fabric. probably I have not integrated fabric correctly. I do not see libcrashlitics.so in apk.
in my gradle there are
apply plugin: 'io.fabric'
crashlytics {
enableNdk true
manifestPath 'src/main/AndroidManifest.xml'
}
I found good article but version is 2.0.0
https://paramsen.github.io/crashlytics-ndk-and-cmake/?readNext=true
Mike from Fabric here. Here's how to setup Crashlytics NDK in your app.
Add these lines to your build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
2) Also in your app's build.gradle apply the Fabric plugin:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
3) Add the Fabric repo:
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
4) Enable NDK as you mentioned:
crashlytics {
enableNdk true
}
5) Add Crashlytics and Crashlytics NDK AARs:
dependencies {
// Crashlytics Kit
compile 'com.crashlytics.sdk.android:crashlytics:2.9.3'
// NDK Kit
compile 'com.crashlytics.sdk.android:crashlytics-ndk:2.0.4'
}
6) In your Java code, add these imports:
import io.fabric.sdk.android.Fabric;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.ndk.CrashlyticsNdk;
7) Init Fabric as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
setContentView(R.layout.activity_sample);
}
and you're done. Don't forget to upload symbols as well:
~ username$ ./gradlew crashlyticsUploadSymbolsRelease

Getting errors while integrating VISA checkout

I am integrating VISA checkout payment using the following link: Visa Checkout Integration in Android Studio.
My project is quite heavy. I had imported it from Eclipse which already contained many libraries. While integrating the VISA checkout, I added the the following in the gradle file, and its associated libraries:
compile(name:'VisaCheckout-Android-SDK-4.3', ext:'aar')
When I executed this code without any previous libraries, I didn't get any errors.
However when I run the code in my existing app in Lollipop, I get a blank screen which does not respond even on clicking the hardware back button.
I'm getting some unusual errors such as:
No subscribers registered for event class com.visa.internal.ˌ
No subscribers registered for event class de.greenrobot.event.NoSubscriberEvent
Rejecting re-init on previously-failed class java.lang.Class
In Kitkat, the app crashes showing java.lang.NoClassDefFoundError: com.google.android.gms.analytics.GoogleAnalytics, (since Google Analytics is integrated in my project).
Here's my gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.fitcompany.fitness_enthusiasts"
minSdkVersion 11
targetSdkVersion 20
}
buildTypes {
release {
multiDexEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
flatDir { dirs 'libs'}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile project(':slidingMenu')
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.paypal.sdk:paypal-android-sdk:2.14.2'
compile(name:'VisaCheckout-Android-SDK-4.3', ext:'aar')
compile files('libs/volley.jar')
compile files('libs/gson-2.3.1.jar')
compile files('libs/HockeySDK-3.5.0.jar')
compile files('libs/httpclient-android-4.3.3.jar')
compile files('libs/ksoap2-android-assembly-3.1.0-jar-with-dependencies.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.5.6#aar') {
transitive = true;
}
}
My libs folder contains the following:
eventbus-2.4.0.jar
gson-2.3.1.jar
HockeySDK-3.5.0.jar
ksoap2-android-assembly-3.1.0-jar-with-dependencies.jar
libGoogleAnalyticsServices.jar
okhttp-2.5.0.jar
retrofit-1.9.0.jar
volley.jar
YouTubeAndroidPlayerApi.jar
VisaCheckout-Android-SDK-4.3.aar
I was using the wrong file in the libs folder. I replaced this line:
VisaCheckout-Android-SDK-4.3.aar
with this one and the error was gone.
VisaCheckout-Android-SDK-2.9.aar
Its because the name of SDK-AAR file in libs folder is in lowercase contrary to one declared in app-gradle.
e.g., 'visacheckout-android-sdk-4.3' instead 'VisaCheckout-Android-SDK-4.3'