Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android应用程序包是否自动从下载的APK加载类?_Android_Android App Bundle - Fatal编程技术网

Android应用程序包是否自动从下载的APK加载类?

Android应用程序包是否自动从下载的APK加载类?,android,android-app-bundle,Android,Android App Bundle,我正在尝试Android应用程序包和动态功能模块。动态模块将与基本模块构建在单独的APK中 我想知道如何在基本模块中使用动态模块中的源代码和类?从play store下载其他APK后,play.core库是否会自动加载这些类?我需要自己处理类加载吗?您可以查看 该示例使用了一个BaseSplitActivity,它覆盖了basecontext,如下所示: override fun attachBaseContext(newBase: Context?) { super.attachBas

我正在尝试Android应用程序包和动态功能模块。动态模块将与基本模块构建在单独的APK中


我想知道如何在基本模块中使用动态模块中的源代码和类?从play store下载其他APK后,play.core库是否会自动加载这些类?我需要自己处理类加载吗?

您可以查看

该示例使用了一个
BaseSplitActivity
,它覆盖了
basecontext
,如下所示:

override fun attachBaseContext(newBase: Context?) {
    super.attachBaseContext(newBase)
    SplitCompat.install(this)
}
这样可以确保在“活动”启动时正确安装新下载的拆分

对于资产,您必须创建一个新的包上下文


例如,我在动态模块中有一些视图。是否可以在基本模块中使用这些视图?我想我可以使用类加载器从下载的APK加载这些视图,但是play core库是否可以帮助我处理这些事情?您必须使用反射来访问这些视图。PyReCo确实考虑到服务/删除模块,而不是访问模块中的代码。
private fun displayAssets() {
    // Get the asset manager with a refreshed context, to access content of newly installed apk.
    val assetManager = createPackageContext(packageName, 0).assets
    // Now treat it like any other asset file.
    val assets = assetManager.open("assets.txt")
    // ...
}