cuplv / droidel

Framework model for static analysis of Android
Apache License 2.0
45 stars 14 forks source link

Cannot find android class in classhierarchy #6

Closed highwater closed 9 years ago

highwater commented 9 years ago

Hi, I found this error:

Exception in thread "Thread-19" java.lang.AssertionError: assertion failed: Couldn't find android.app.Fragment in class hierarchy
    at scala.Predef$.assert(Predef.scala:165)
    at edu.colorado.droidel.constants.AndroidLifecycle$$anonfun$getFrameworkCreatedClasses$1.apply(AndroidLifecycle.scala:97)
    at edu.colorado.droidel.constants.AndroidLifecycle$$anonfun$getFrameworkCreatedClasses$1.apply(AndroidLifecycle.scala:95)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.Iterator$class.foreach(Iterator.scala:743)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1177)
    at scala.collection.MapLike$DefaultKeySet.foreach(MapLike.scala:174)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.AbstractSet.scala$collection$SetLike$$super$map(Set.scala:47)
    at scala.collection.SetLike$class.map(SetLike.scala:92)
    at scala.collection.AbstractSet.map(Set.scala:47)
    at edu.colorado.droidel.constants.AndroidLifecycle$.getFrameworkCreatedClasses(AndroidLifecycle.scala:95)
    at edu.colorado.droidel.driver.AndroidAppTransformer.makeFrameworkCreatedTypesMap$1(AndroidAppTransformer.scala:400)
    at edu.colorado.droidel.driver.AndroidAppTransformer.doInstrumentationAndGenerateHarness(AndroidAppTransformer.scala:416)
    at edu.colorado.droidel.driver.AndroidAppTransformer.transformApp(AndroidAppTransformer.scala:533)

I tested an APK with API level 10, so it's using support library to use Fragment. I would love to trace this but unfortunately I don't know Scala for now. In my understanding, droidel should not search for android.app.Fragment if the apk is using api < 11, right?

Edit: anyway, i think i should check with another apks

sblackshear commented 9 years ago

Pietro also reported seeing this error a lot. I think the cause is related to what you suggest. Will look into it today.

sblackshear commented 9 years ago

I pushed a fix to make this a soft error instead of causing a crash. However, I think the root cause of this is using a mismatched version of the Android library, as you suggest.

highwater commented 9 years ago

Thanks, Sam. Hope you can fix this soon.

highwater commented 9 years ago

Wait i think the issue should be left open until it's properly fixed.

sblackshear commented 9 years ago

Oh, I don't think there's anything I can do to fix this. The user decides what version of the Android library to use via the -android_jar flag. I don't think there's anything I can do to prevent the soft error if the user decides to use the wrong version :). I suppose I could include all of the JARs as part of the Droidel project and automatically select which one to use. However, this would take away the ability to test how an app behaves with different (manually selected) versions using Droidel, which I think is valuable.

highwater commented 9 years ago

Hmm that's true. But why, in the first time, droidel looks for android.app.Fragment when the app itself doesn't use it? And the problem I think won't be only applied to Fragment class but to every class that has support version.

sblackshear commented 9 years ago

The "looking for android.app.Fragment" that you describe is how Droidel determines whether an app is using Fragment's or not. The problem is that Droidel previously crashed on failure to find android.app.Fragment in any app (even one's that don't use Fragment's), which was definitely a bug. I fixed that bug yesterday, though you may still get a spurious log message about not finding Fragment that you can ignore.

highwater commented 9 years ago

Ah i see, so the problem is only with Fragment then?

sblackshear commented 9 years ago

Fragment's are the only lifecycle type I support that doesn't exist in every version of the Android library, so I think this problem should just be limited to Fragment's.

highwater commented 9 years ago

That's good to know, thanks for the explanation :)