Jetpack Compose 'Deploy Preview' crashes due to Firebase Performance - android

I would like to use Jetpack Compose's 'Deploy Preview' functionality. After I tried to deploy, my app crashed due to Firebase Performance. I tried a several unsuccessful solutions, so I'm looking for additional advice.
Stacktrace
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.myapp.android.legacy.test. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:186)
at com.google.firebase.perf.FirebasePerformance.getInstance(FirebasePerformance.java:132)
at com.google.firebase.perf.FirebasePerformanceInitializer.onAppColdStart(FirebasePerformanceInitializer.java:29)
at com.google.firebase.perf.application.AppStateMonitor.sendAppColdStartUpdate(AppStateMonitor.java:322)
at com.google.firebase.perf.application.AppStateMonitor.onActivityResumed(AppStateMonitor.java:240)
at android.app.Application.dispatchActivityResumed(Application.java:455)
at android.app.Activity.dispatchActivityResumed(Activity.java:1291)
at android.app.Activity.onResume(Activity.java:1819)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1454)
at android.app.Activity.performResume(Activity.java:8111)
...
Solution 1
I removed FirebasePerformance from Kotlin and Java files. Same error.
Solution 2
In addition to solution 1, I deleted FirebasePerformance from gradle files. Deploying worked! But I still need Firebase Performance.
Solution 3
The Firebase Performance Monitoring Plugin and Library were disabled via Disable the library at compile time, but do not allow your app to enable it at runtime and Disable the plugin via a Project Property flag. No effect on the crash.
Solution 4
Downgraded com.google.gms:google-services from 4.3.14 to 4.0.0 - compile error: Cannot invoke method get() on null object. Downgraded to 4.2.0 - original issue
Solution 5
Manually called FirebaseApp.initializeApp(this); in MyApplication.onCreate(). The issue remained the same.
Specs
Android Studio Dolphin 2021.3.1 Patch 1; Kotlin version 1.6.10; Android Tools version 7.0.4; Samsung Galaxy S8 running Android 10

Related

Android Studio xml preview issue failed to initialize editor

After Update android studio dolphin my old projects xml preview not showing views. Is anyone facing same issue? And have done solution then please share it here.
It's run perfectly fine but preview not working.
What I did tried?
File -> Invalidate Cashes / Restart
Delete build , idea , gradle folder
Restart PC and android studio
but none of that solved my problem.
In my case, I have upgraded the project AGP (Android Gradle Plugin) and then restart the android studio.
Problem Solved.
I'm suffering from same issue/bug. What I did so far?
Attempt 1
File -> Sync Project with gradle files
File -> Invalid catch and Restart.
Delete build folder idea and .gradle folder.
Restart Android studio and restarted my pc as well.
This will do solve in one of the my project which is only 5 screen project. But not solved in my other old projects which are more than 5 year old.
Attempt 2
Tried all step from attempt 1 Also tried what siregar2103 answered
File -> Repair IDE but still have same problem ,But Repair IDE did solve my other project issue/bug.
Attempt 3
All from Attempt 1 and 2 but not solve in my main project so I decided to upgrade my years old project to latest one.
I did upgrade my Gradle from 4.1.3 to 7.3.0
Update all dependency to latest one but I face many error while doing that.
Hilt error and other errors too. Which I'm going to mention below.
For Hilt I did removed all old Hilt related library and and below
kapt "com.google.dagger:dagger-compiler:2.42"
kapt "com.google.dagger:hilt-android-compiler:2.43.2"
implementation "com.google.dagger:dagger:2.42"
implementation "com.google.dagger:hilt-android:2.43.2"
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation "androidx.navigation:navigation-compose:2.5.1"
In build.gradle file (not .app level)
id 'com.google.dagger.hilt.android' version '2.43.2' apply false
Important note: I did add implementation "androidx.navigation:navigation-compose:2.5.1" dependency because I got
java.lang.IllegalArgumentException: CreationExtras must have a value
by SAVED_STATE_REGISTRY_OWNER_KEY error in runtime.
Other Error which I faced is
Exception is:
com.intellij.openapi.externalSystem.model.ExternalSystemException:
lateinit property _buildFeatureValues has not been initialized
For this I did build gradle using command line and it give me full error which I didn't get when I directly build don't know why? But It's through error related flat dir and aar file so I did removed flat dir code and change aar file implementation code now It's started to build and my app started to install.
Now still some of my file not rendering and that because of I'm using custom attr from style so I'm trying to figuring out why it's happening and I'll update this answer when I find solution for that.
So using above my 60% xml files preview start showing in my old projects. For 40% screen I have to change my default theme to custom theme in preview of xml so it can start rendering.
Repair IDE
Upgrade your code to latest Android Gradle Plugin
This 2 step should solve your problem. And build using command line for more error related details.
Have you try to using Repair IDE? It works for me
I ran into a similar issue when upgrading to Dolphin. I was able to solve this by changing the preview's theme from App.Starting [default] to my app's theme.
Try to update the gradle and sync files. It work for me.
The XML file in your project may contain an error. The reason may be a font issue or a file not linking correctly with your XML layout.
This is for your reference on how to find errors.
Hope you find it useful.
Check what Layout Inspectors you have enabled in Android Studio and try to let only the API 29-30 inspector active.
In my case if in xml custom views have used that my preview screen not show views if I remove or comment custom views in xml layout after that the preview screen show other view perfectly
I know removing custom layouts not solution.
for solve this issue I do following steps
First I just update Gradle plugin version to 7.3.0 from setting project structure (No working)
after that I also update com.google.gms:google-services version to 4.3.14
now every things work fine.
In my case, I have upgraded Android Gradle Plugin when update is popUp and then restart the android studio.
My Problem Solved.
I am looking as well for a soluition till now.
From what i see, it has something to do with
AGP or Cardview (Layouts). Many code snipeets relate to this issue.
I am trying to update the AGP version, but it seems, that the enveronmet is more broken than that.
I get as well an empty Field for the gradle version and plugin under settings.
For anyone can not fix this issue, i'm just need to update gradle version and buildtool
buildSrc/src/main/kotlin/Dependencies.kt
object BuildPlugins {
object Versions {
const val buildToolVersion = "7.3.0" //lower version seem not work
and change to 7.4 in gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip

Incorrect configuration. Please configure your build for VectorDrawableCompat with Gradle 7.0.2

My app, which was working before, suddenly started crashing in my LaunchActivity with: Please configure your build for VectorDrawableCompat. This is happening with Gradle 7.0.2, which doesn't make sense since other posts regarding this issue are from 3 years ago and recommend updating to gradle 2.0+ (which is much older) and also using the latest android support library (which is a non-issue now with androidx). They also recommend setting vectorDrawables.useSupportLibrary = true which has already been the case in my app. So those posts weren't relevant to my issue.
minSdkVersion 21
targetSdkVersion 31
vectorDrawables.useSupportLibrary = true
classpath 'com.android.tools.build:gradle:7.0.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
Oddly this started happening on my master after I switched to a different branch and then returned to my master branch after a month. However, the master branch shouldn't have changed at all and it must have been working before, because I cut a production release from it that previous month, and the production release wasn't crashing.
Caused by: java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.
at androidx.appcompat.widget.ResourceManagerInternal.checkVectorDrawableSetup(ResourceManagerInternal.java:495)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:140)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:480)
at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:93)
at androidx.appcompat.app.AppCompatDelegateImpl.attachToWindow(AppCompatDelegateImpl.java:797)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureWindow(AppCompatDelegateImpl.java:773)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreate(AppCompatDelegateImpl.java:501)
at androidx.appcompat.app.AppCompatActivity$2.onContextAvailable(AppCompatActivity.java:131)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:297)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at com.somewearlabs.sw.ui.LaunchActivity.onCreate(LaunchActivity.kt:14)
at android.app.Activity.performCreate(Activity.java:7963)
at android.app.Activity.performCreate(Activity.java:7952)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
I finally fixed the issue. When I was inspecting the crash in Android Studio, clicking on the file/line number link (eg. "ResourceManagerInternal.java:495") opened up two options for the class, one in appcompat library version 1.2.0 and also 1.3.0. There must have been two versions used in my dependencies, even though in the build.gradle files for all of my projects explicitly stated androidx.appcompat:appcompat:1.2.0. Using a breakpoint showed that the line in 1.3.0 was getting called when launching the app.
Then I did File > Invalidate Caches and Restart.
I thought that ensuring that only one version of appcompat being used in the project might fix things, so I switched all the build.gradle files from using androidx.appcompat:appcompat 1.2.0 to 1.3.0. After resyncing/building, the crash went away. I don't know why this crash started happening in the first place - if anyone could shed some light on this - but I needed to update the appcompat dependency anyway so it worked out.

Android app crashes when adding firebase crashlytics

I'm migrating from fabric to firebase crashlytics. I've been able to migrate to AndroidX (which I believe was necessary). Then I followed this steps but the app crashes when I add the crashlytics dependency (everything works if I comment out the crashlytics implementation line).
implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
When using a physical phone, I don't get any error, just some SQLiteEventStore and JobInfoScheduler log and the sigkill:
https://gist.github.com/raquelhortab/60ebd50ead5aa820c34bc271a09e94b7
When using an emulator I get an okhttp3 error (you can see it in the gist above). Again, the only difference is the crashlytics line in the app's build.gradle.
The okhttp3 error made me think I might have to update glide and okhttp3 (which is not that easy) but it works just fine without crashlytics so I don't think that's the problem.
I've also tried the crashlytics version 17.2.2 and newer versions of firebase-related implementations, you can find the gradle files in the gist as well.
PS: I apologize if this has already been answered, searching crashes and crashlytics leads to many questions of crashes that are not realated to crashlytics (which is logic)
It doesn't seem firebase issue from the error stack provide. Try to add the same version for com.squareup.okhttp3:logging-interceptor and com.squareup.okhttp3:okhttp
try 3.4.1

Android Databinding build fail after Gradle plugin update with migration to annotationProcessor

To support Instant Run in my version of Android Studio, I needed to upgrade my Gradle plugin from version 2.2.3 to 2.3.3
I'm aware I'm supposed to migrate to annoationProcessor and I believe I've followed that guide correctly
after doing so, the Android DataBinding code generation fails
The migration guide linked earlier states that all I need is to
Make sure you are on the Android Gradle 2.2 plugin or newer
Remove the android-apt plugin from your build scripts
Change all apt, androidTestApt and testApt dependencies to their new format
This should be all that's needed to successfully build the project. Yet it doesn't build.
Build output
Gradle build finished with 101 error(s) and 23 warning(s) in 12s 481ms
All of the errors follow the same pattern:
C:\Users...\FooAdapter.java
error: package com.example.app.databinding does not exist
error: cannot find symbol class ItemFooBinding
An interesting message can be found in the build console:
Warning:The following options were not recognized by any processor: '[android.databinding.minApi, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir, android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.isTestVariant]'
I would like to point out that...
I presume I don't have an error in some XML file, binding expression or a naming issue. The same set of sources and XML build when I switch back to the Git branch with the old gradle plugin version (and all of the other source files up-to-date)
I did increase the limit of output build errors as discussed here, although this doesn't seem to be relevant right now, since as you can see, I currently have "only" 101 errors. :)
Additional info
The following diffs show how I've modified my gradle files:
build.gradle DiffChecker link
app/build.gradle DiffChecker link
Also, as a quick overview, here is the list of some of the "more interesting" plugins & libraries used by the project:
Kotlin
Android DataBinding
Realm
Retrofit
Dagger
ButterKnife (I know...)
Multidex Support Library
Does anyone have a clue what could be the issue? Any help or idea will be greatly apprecitated!
I had exactly the same warning. This line in gradle solved the issue:
kapt "com.android.databinding:compiler:3.0.1"
Hopefully, it will help somebody
Update:
3.0.1 is Android Plugin Version.
When you see innumerable build errors mentioning databinding as in this case, the problem usually lies somewhere else. Databinding just gets stopped in its tracks by unrelated build problems and complains exceedingly loudly. The only way to deal with it is to locate the build errors that are not tied to databinding. Once they are fixed, databinding can do its thing again and be silent. Unfortunately you often have to repeat this approach several times until you have found all non-databinding issues. It's an arduous task for sure, but unfortunately there is nothing else you can do until Google manages to provide a saner build environment.
This is the reason why you are advised to increase the build error limit beyond 100 - you would not see the actual errors causing your problems, because they commonly do not show up early in the list.
I will chance a guess - Dagger 2 is a common source of triggering this problem, which could be related to your annotationProcessor change; so look out for Dagger errors. But your issues could be caused by other things, like other annotation processors as you mentioned - you wouldn't know for sure until you diligently dig through your build errors.
It seems it all comes down to my project using Kotlin. Actually we have it mixed: some classes use plain old Java while others are written in Kotlin. An incomplete migration. :)
I assume that without Kotlin, replacing apt with annotationProcessor would be enough and I wouldn't have ran into this issue at all.
Solution
Annotations need to be processed by both annotationProcessor and kapt, which seems to be Kotlin's own annotation processor.
For each Gradle dependency that uses annotations, you should have both of the following in your app-level build.gradle:
annotationProcessor 'com.example.my.library:x.y.z
kapt 'com.example.my.library:x.y.z

Build error with Android Studio 3.0 Canary 4

I am currently in the process of developing an Instant app, for which I have restructured my monolithic app into feature modules.
Everything was up and running till Android Studio canary 3, but after an update to Android Studio Canary 4 my project fails to build with the following error:
A problem was found with the configuration of task ':minimoBase:dataBindingExportBuildInfoDebugAndroidTest'.
> Directory '/Users/nayak.vishal/projectData/minimo_instant_app_project/putica-client-android-
native/minimoBase/build/intermediates/data-binding-info/androidTest/debug'
specified for property 'xmlOutFolder' does not exist.
The following procedure worked as a workaround for this issue:
Execute the following build commands on the gradle command line
1) gradlew clean
2) gradlew :appModule:assembleDebug
here appModule is the name of the app module for building the installable apk
the build is successful and the debug apk generated in the output folder can be installed successfully
3) gradlew :instantAppModule:assembleDebug
here instantAppModule is the name of the instant app module
the build is successful and the instant app apks can be installed and launched via deep link
Once the above command line builds are successful, building via Android Studio Canary 4 also stops throwing the build error.
I got similar error when I turn on data-binding for library module. When I turn it off and move all classes that require data-binding to app module, it works. So I guess there is a problem that DataBinding doesn't work on Library module any more ( Gradle 2.x fine with this).
dataBinding {
enabled = false
}
I am using com.android.tools.build:gradle:3.0.0-alpha5 and Android Studio 3.0 Preview Canary5
UPDATE
Although the original answer worked, I really want to turn on data-binding on my library module, where I implement some base classes using binding technique. I move them back to library module and upgrade kotlin version to the latest one 1.1.3-2. Suddenly it works also. I am not sure which one is the better but both ways work for me.
UPDATE 2
I am using com.android.tools.build:gradle:3.0.0-alpha9 and kotlin 1.1.3-2 at this time and suddenly the problem re-appear.
Now I think the problem doesn't come from Kotlin. My library module turned dataBiding { enabled=true}, but it doesn't have any layout file. I tried to create a fake layout file wrapped by <layout> tag and it works
<?xml version="1.0" encoding="utf-8"?>
<layout>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</layout>
In your gradle.properties file , add the following line
android.enableAapt2=false
Recent versions of AS3.0 switched to using AAPT2 by default.
You can disable AAPT2 in your gradle.propertіes fіle with above mentioned line of code, and continue developing on AS3 canary 4.
This was an issue for me when I had a "base" feature module without any layouts (all my actual layouts are in separate features)
Adding a dummy layout XML file in the base feature (e.g. as base/src/res/layout/dummy.xml) meant the missing directory was created and the app compiled.
(this is using com.android.tools.build:gradle:3.0.0-alpha6)
I've had the same problem, seems like a bug in Canary 4.
For now, as a workaround, I downgraded to Android Studio 3.0.0 Canary 3 (This is an archive of all Android Studio releases) and also downgraded the Android Gradle plugin to 3.0.0-alpha3:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
...
}
Updated:
Just check the Canary version after update. For that see Android Studio version just above the toolbar (File..Edit..View..line) where name at end like "Canary X".-> X is number like 3,4,5,etc.
For example suppose updated version(X) is 5.
Try to change that classpath in build.gradle(applicationName) to 3.0.0-alpha5 and sync(/Try) again:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha5'
}
Means that updated version(X):-
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alphaX'
}

Categories

Resources