ApplicationPackageManager

ApplicationPackageManager

robolectric migration guide编译以下示例时

package com.jongla.soundmash.robolectric
import org.robolectric.shadows.ShadowApplicationPackageManager
import org.robolectric.annotation.Implements
import android.app.ApplicationPackageManager

@Implements(value = ApplicationPackageManager.class, inheritImplementationMethods = true)
class MyCustomPackageManager extends ShadowApplicationPackageManager {
}


AndroidStudio给了我Unresolved reference: ApplicationPackageManager。有谁知道我需要做些什么才能编译该示例?我是否需要在gradle中添加一些其他testCompile软件包?

最佳答案

在查看Roboloectric源代码时,我发现了属性className来指定类名。它像魔术一样工作。

@Implements(className = "android.app.ApplicationPackageManager", inheritImplementationMethods = true)
public class MyCustomPackageManager extends ShadowApplicationPackageManager {
}


当建议使用值作为ApplicationPackageManager类是私有的并且对于用户代码不可见时,迁移文档显然是不正确的。

关于android - 找不到android.app.ApplicationPackageManager,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44473236/

10-10 06:28