ATM I have an application in the field with a working, basic Crashlytics support - I can see the crashes coming in my Firebase console.
Now, I'd like to add some custom info to the stacktraces coming. Crashlytics docs state that I can add custom 'keys' in the following way:
Crashlytics.setString(key, "foo" /* string value */);
They however fail to mention what do I have to import here for the compiler to resolve the 'Crashlytics' symbol? Googling doesn't help....
Well, it turned out that Crashlytics's own docs are not up-to-date. Even though this official page clearly says to do
Crashlytics.setString(key, "foo" /* string value */);
and then iike Oleg says the right import would be
com.crashlytics.android.Crashlytics
but earlier on the same Crashlytics docs page advises to add the following dependency
// Add the Firebase Crashlytics dependency.
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta04'
where com.crashlytics.android.Crashlytics doesn't exist.
Correct (at least at the moment, Crashlytics seems to be changing in non-compatible ways) way seems to be include the dependancy in 'build.gradle' as given above and then
import com.google.firebase.crashlytics.FirebaseCrashlytics;
(...)
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
crashlytics.setCustomKey("key", "value" );
That should be resolved by this import statement
import com.crashlytics.android.Crashlytics;
Related
I've made a timestamped versionName in build.gradle like 20150707.1125. I want to show the version of the package in react-native app in about window. How I could get versionName in code?
I've successfully used the React Native Device Info component to get the build details as specified in the Gradle config.
Once installed you can use:
DeviceInfo.getVersion()
To output the version, and:
DeviceInfo.getBuildNumber()
To get the build number.
If you want the version number in your package.json, you can also do:
var pkg = require('./package.json');
console.log(pkg.version);
import { version } from './package.json';
I couldn't get the package react-native-device-info to work. Ran into this issue Might need some gradle and java changes to make it fly.
Anyhow I got what I needed react-native-version-number. And I am happy with it.
import VersionNumber from 'react-native-version-number';
console.log('appVersion:', VersionNumber.appVersion)
Oh, and as it relates to gleaning the version from package.json. It feels wrong to me. I mean I had to try it just to see if it would work. I didn't realize that resource would be available at runtime on the device. It does work, but I also have some buildTypes debug foo going on in my build.gradle I learned here. So its nice to be getting the versionName like 0.1.7-debug straight from the horses mouth.
You can use react-native-device-info
And you can get app version for both iOS and Android by calling following method.
const version = DeviceInfo.getVersion();
// iOS: "1.0"
// Android: "1.0"
Hope this will help.
I used as reference the answer by #Marcos Demetrio
But I was using expo, so I did this:
import {expo} from '../../app.json'
And in the Component:
<Label>{expo.version}</Label>
No package install needed.
If you are using expo and you want lighter lib, use expo-application:
import * as Application from 'expo-application';
Application.nativeApplicationVersion //returns a string
// or
Application.nativeBuildVersion //returns a string
react-native-version-number library works for both Android and iOS. You can find installation instructions here. Remember that in current versions of ReactNative linking libraries is not needed anymore (omit linking while installing - it was not written in the instruction)
https://github.com/APSL/react-native-version-number
import VersionNumber from 'react-native-version-number';
...
render() {
var versionNumber = `${VersionNumber.appVersion}.${VersionNumber.buildVersion}`;
return (
<Text style={ styles.versionText }>v. {versionNumber}</Text>
)
}
...
I used the following snippet to extract version info using package.json:
import PackageJson from '../../../package' // where package is the package.json file
console.log('version', PackageJson.version)
Hope it helps.
I tried most of the thing to fix this nicely and I and happy to see detailed description for doing everything that I needed react-native-version-check
import { Linking } from 'react-native';
import VersionCheck from 'react-native-version-check';
VersionCheck.needUpdate()
.then(async res => {
console.log(res.isNeeded); // true
if (res.isNeeded) {
Linking.openURL(await VersionCheck.getStoreUrl()); // open store if update is needed.
}
});
If you use Expo Framework, you can use expo-constants package as documented in https://docs.expo.dev/versions/latest/sdk/constants/.
For me, this is working: grabs the version and description from the app.json: https://github.com/marcoXbresciani/TKCompanionApp/blob/0.1.12/screens/about/Version.tsx
So, only one point where to store things.
I think the easiest way is to set a version number in App.js just like a variable, and ensure it is global (gettable from the whole app)
const version = "1.0.0"
and do this i every build
I am trying to implement custom lint checks (using Kotlin). I have set up a module for my custom checks and added classes to test my first lew lint check, mostly following these two tutorials here and here.
So I now have a module, I have a custom IssueRegistry, I've created an issue and a Detector class for it. So far it seems complete. I've added a test to check if my lint check works and it looks alright.
I have added my module to the project by referencing it in settings.gradle like this: include ':app', ':somemodule', ':mylintmodule'
Now if I run the linter using ./gradlew lint I get a lint result file telling me this:
Lint found an issue registry (com.myproject.mylintmodule) which requires a newer API level. That means that the custom lint checks are intended for a newer lint version; please upgrade
Lint can be extended with "custom checks": additional checks implemented by developers and libraries to for example enforce specific API usages required by a library or a company coding style guideline.
The Lint APIs are not yet stable, so these checks may either cause a performance degradation, or stop working, or provide wrong results.
This warning flags custom lint checks that are found to be using obsolete APIs and will need to be updated to run in the current lint environment.
It may also flag issues found to be using a newer version of the API, meaning that you need to use a newer version of lint (or Android Studio or Gradle plugin etc) to work with these checks.
To suppress this error, use the issue id "ObsoleteLintCustomCheck" as explained in the Suppressing Warnings and Errors section.
So it tells me that I am using a newer API verion in my custom lint check, right? This is my custom IssueRegistry (minus some parts not relevant for this problem):
class MyCustomIssueRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(ISSUE_NAMING_PATTERN)
override val api: Int = com.android.tools.lint.detector.api.CURRENT_API
override val minApi: Int = 1
}
From googling this problem and finding this issue I figured I have to override and set the right API version (and maybe the min API?) by overriding these properties like I did above (this version is my last attempt, directly taken from that issue).
So this property can be set to values between -1 and 5, meaning this (taken right out of the lint.detector.api class):
/** Describes the given API level */
fun describeApi(api: Int): String {
return when (api) {
5 -> "3.5+" // 3.5.0-alpha07
4 -> "3.4" // 3.4.0-alpha03
3 -> "3.3" // 3.3.0-alpha12
2 -> "3.2" // 3.2.0-alpha07
1 -> "3.1" // Initial; 3.1.0-alpha4
0 -> "3.0 and older"
-1 -> "Not specified"
else -> "Future: $api"
}
I have tried all of them, plus the one above adding a minApi override too, and I keep getting the exact same result for each of them.
Also I am unable to locate what other API version this is compared with. Is there a place where this is set for the regular linter in an Android project?
It's also unclear to me what I have to do to make sure my changes got applied - is it enough to change some code, then run lint, or do I have to compile the project first, or build & clean?
Following the tutorials, I added my custom lint check by adding this to the app's build.gradle: lintChecks project(":mylintmodule")
Is that even right? The API issue on my registry class shows up no matter if my lint check is referenced (and hopefully used) like that or not. I have also tried the other method described in the first tutorial, adding this task to the linter module build.gradle:
defaultTasks 'assemble'
task copyLintJar(type: Copy) {
description = 'Copies the lint jar file into the {user.home}/.android/lint folder.'
from('build/libs/')
into(System.getProperty("user.home") + '/.android/lint')
include("*.jar")
}
// Runs the copyLintJar task after build has completed.
build.finalizedBy(copyLintJar)
But since I can't figure out how to see if my custom checks are actually run, I don't know if that works as intended either.
So how do I get this warning resolved (since I interpret the text as "As long as the versions don't match I will not try to run your lint check"), and how can I make sure my lint check is actually run by the linter?
I am trying to customize the firebase in-app-messaging-display's UI of "Image Only" and "Modal" mode. So I turned to the official documentation, but it is quite simple, by saying:
Creating your own display is a two step process:
1.Write your own implementation of the FirebaseInAppMessagingDisplay class.
2.Register that implemenation with the headless Firebase In-App Messaging SDK.
I wonder how can I import in-app-messaging-display's source code into my project and make it work as a library.
I have downloaded its source code from github:https://github.com/firebase/firebase-android-sdk/tree/master/firebase-inappmessaging-display, tried to import it as a module, but after I selected the Source directory, Android Studio hints that: Specify location of the Gradle
or Android Eclipse project. I also have tried to copy the source code into my project's libs directory and added this: include ':libs:firebase-inappmessaging-display' into my settings.gradle file and this: implementation project(':libs:firebase-inappmessaging-display') into my app's gradle dependency. When sync building Android Studio reports errors like this:
ERROR: Unable to resolve dependency for ':XXXXXXXX': Could not resolve project :libs:firebase-inappmessaging-display.
Any suggestion will be highly appreciated.
The information on the doc is little bit confusing. I am also stuck with the same problem for long time. Actually its very simple.
Add these dependencies in your app level gradle file.
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation ("com.google.firebase:firebase-inappmessaging:17.0.3")
Register Your DisplayMessage component on starting activity.
import com.google.firebase.inappmessaging.FirebaseInAppMessaging
import com.google.firebase.inappmessaging.FirebaseInAppMessagingDisplay
///////
override fun onStart() {
super.onStart()
Log.e("MESSAGE", "activity started")
var firebaseInAppMessagingDisplay = FirebaseInAppMessagingDisplay { inAppMessage, cb ->
// You can show the message here.
// The variable inAppMessage has all information about the campaign that we putting in console (title, content, image url.. etc)
Log.e("MESSAGE", "Display Message callback invoked")
}
FirebaseInAppMessaging.getInstance().setMessageDisplayComponent(firebaseInAppMessagingDisplay)
}
After I successfully integrated flurry SDK into the library by using this code in my build.gradle file.
compile 'com.flurry.android:analytics:6.2.0'
I created java Class to integrate my API Key into my code, but I faced this probleme and I have no clue what should I do to successfully integrate it
-cannot resolve symbol FlurryAgent
-cannot resolve symbol flurrylistener
PS: I'm new to Flurry analytics and Android Studio
For now just remove the withListener() line.
It's not necessary to initialize Flurry.
Once you have your integration working, you can go back and set it up if you want, I've found it only to be necessary if you need to send events before Flurry completes initialization.
Flurry is working to get this corrected. Joel Duggan is correct the listener is "only necessary if you need to send events before Flurry completes initialization."
We will be removing this line of code from the basic instructions:
.withListener(flurryListener)
And here is the correct syntax for those who need it:
import com.flurry.android.FlurryAgentListener;
....
FlurryAgent.Builder()
.withLogEnabled(true)
.withListener(new FlurryAgentListener() {
#Override
public void onSessionStarted() {
// Session handling code
}
})
.build(this, 'your_api_key');
I was facing same problem, I have updated gradle and my problem is solved. Use latest gradle as follows,
//Flurry
compile 'com.flurry.android:analytics:7.0.0#aar'
for more reference use this url
for reporting my Application Crashes use Acra library via Android Studio Gradle Dependencies in this form :
dependencies {
compile 'ch.acra:acra:4.6.2'
}
Now in Bebug version it work and return crash report goodly but after export Release version of application not work and return this error in logcat :
Not adding buildConfig to log. Class Not found : " + className + ". Please configure 'buildConfigClass' in your ACRA config
Then i use acra-4-6-2.jar file instead dependencies but not work still!
Too before saw this link but was not helpful fore me.
With thanks for your attention
It sounds like you are Proguardng your app on release but have not added the relevant ACRA classes to your Proguard config.
See https://github.com/ACRA/acra/wiki/ProGuard
None of the other answers actually provided the fix.
To fix this issue, assign your BuildConfig.class to the buildConfigClass field on your ReportsCrashes annotation declaration.
#ReportsCrashes(
buildConfigClass = BuildConfig.class )
public class YourApplication extends Application { ... }
If you are using so called "dynamic" configuration you are probably having "empty" annotation like #ReportsCrashes().
In that case it turns out that ACRA does not create proper default config. The solution is simple: just add some fake property there like:
#ReportsCrashes(formUri = "placeholder")
which you will later override in the dynamic config...