Comments (7)
Sorry for the late reply, I haven't had a chance to check it out yet. Ok, thanks to your advice regarding pro guard and mapping.txt, I was able to see where the crashes happen originally. To summarize: After reading you answers again carefully, I understood it in detail. The main problem was the constructor. I have removed them in all my fragments and added a companion object with a newInstance-Method. No crashes anymore! Thank you my friend, you saved me a lot of trouble - again! 🙏❤️
from simple-stack.
@metinvio did you ever figure this out?
What is o2.w2
in your Proguard mapping, is it YOUR class? Maybe it's something like MapFragment used from <fragment
and Proguard actually doesn't keep its constructor.
from simple-stack.
@metinvio hello, glad to hear simple-stack is working well! Based on your stack trace (q2.v1
) being obfuscated, I would expect that you either have Fragments with multiple constructors (you should only have no argument constructor on a fragment), or the Fragment's constructor is removed by R8 in release mode.
You could try these proguard-rules.pro additions:
-keepclassmembers public class * extends android.support.v4.app.Fragment {
public <init>(...);
}
-keepclassmembers public class * androidx.fragment.app.Fragment {
public <init>(...);
}
In general, I expect this to be a process death crash caused by having non-empty fragment constructor. You should always use empty constructor + pass args with setArguments()
(with simple-stack and DefaultFragmentKey
/DefaultFragmentStateChanger
, this already happens and passes the @Parcelize data class YourKey(..
as an argument. If you extend from KeyedFragment
then you can use getKey()
, if you don't then requireArguments().getParcelable(DefaultFragmentKey.KEY_ARGS)
.)
from simple-stack.
@Zhuinden thank you for the quick response.
I doubt that this is caused by Proguard. Because it also happens in debug mode where proguard is disabled.
But I think the second part of your answer is more likely the cause. I will check that and will let you know - thanks a lot 😊
from simple-stack.
@metinvio Did you succeed in figuring out the cause?
from simple-stack.
Hi @Zhuinden ,
no unfortunately it's still the same. I changed all my Fragment to this:
class MyFragment: Fragment() {
...
companion object{
fun newInstance(name : String) : MyFragment {
val args = Bundle()
args.putSerializable(ARG_NAME, name)
val fragment = MyFragment()
fragment.arguments = args
return fragment
}
}
}
and I still get crash reports like following:
java.lang.NoSuchMethodException - o2.u2. []
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxxxxxx/com.xxxxxxxxx.activities.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment o2.w2: could not find Fragment constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4166)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4312)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2571)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8741)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
In RootScreen I'm calling them like:
override fun bindServices(serviceBinder: ServiceBinder) {
with(serviceBinder) {
add(FragmentStackHost(Screen1()), SCREEN1_STACK)
add(FragmentStackHost(Screen2()), SCREEN2_STACK)
add(FragmentStackHost(Screen3()), SCREEN3_STACK)
add(FragmentStackHost(Screen4)), SCREEN4_STACK)
add(FragmentStackHost(Screen5()), SCREEN5_STACK)
}
}
and inside NavigationKeys.kt like:
@Parcelize
class Screen1 : DefaultFragmentKey() {
override fun instantiateFragment(): Fragment = MyFragment.newInstance()
}
from simple-stack.
Theoretically if you have a noarg constructor that you call from code, then it can't be removed by Proguard. It would be nice to know what o2.u2.
and o2.w2
is based on your Proguard mapping
file (it's in the build outputs) so that you can troubleshoot more.
Btw, make sure your keys are data class
(or data object
) as per the readme.
from simple-stack.
Related Issues (20)
- What is the proper way to add a key to the top even if it already exists in the backstack? HOT 2
- Publish to MavenCentral instead of just Jitpack.io HOT 2
- How to 'lookup<>()' scoped class from an Android Service HOT 2
- Lazy initialization of ScopedServices HOT 2
- KMM support? HOT 2
- Screen can get the service from wrong scope during back animation HOT 6
- Backstack is not available in a child Fragment's onCreate after process death
- DialogFragment and BottomDialogFragment as part of navigation stack, question HOT 2
- Verify that the new `setParentServices()`'s `lookupFromScope(..., EXPLICIT)` behavior is what is expected HOT 1
- Updating the Compose example to Compose 1.5.0 requires AGP 8.1
- Should Simple Stack be used in new projects HOT 14
- Crash due to activity.onBackPressed() when removing fragment hosting a WebView in AndroidView {} + FADE HOT 15
- Backstack with espresso HOT 3
- The service does not exist in any accessible scopes HOT 11
- Up navigation examples are hard to find HOT 4
- Consider adding Backstack.services() method as in GlobalServices.services() HOT 4
- Extensions should support Fragment in-app predictive back animations
- How to write unit tests based on the readme example HOT 3
- Synthetic up scopes for keys
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-stack.