Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getApplicationInfo有两处实现,且实现不一致。 #40

Closed
shifujun opened this issue Jul 11, 2019 · 3 comments · Fixed by #46
Closed

getApplicationInfo有两处实现,且实现不一致。 #40

shifujun opened this issue Jul 11, 2019 · 3 comments · Fixed by #46

Comments

@shifujun
Copy link
Collaborator

com.tencent.shadow.core.runtime.ShadowContext#getApplicationInfo
com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo
两处实现的逻辑不一致,且不应该实现两遍。

其中com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo返回的ApplicationInfo没有设置sourceDir,导致了问题#38

其中ShadowPackageManager是插件中代码通过PackageManager试图getApplicationInfo,并且传入的packageName等于插件(也等于宿主)的。我们认为这种调用实际上是试图拿到插件自己的ApplicationInfo。因此转调过来了。

@ehunmayh
Copy link

com.tencent.shadow.core.runtime.ShadowContext#getApplicationInfo
com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo
两处实现的逻辑不一致,且不应该实现两遍。

其中com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo返回的ApplicationInfo没有设置sourceDir,导致了问题#38

其中ShadowPackageManager是插件中代码通过PackageManager试图getApplicationInfo,并且传入的packageName等于插件(也等于宿主)的。我们认为这种调用实际上是试图拿到插件自己的ApplicationInfo。因此转调过来了。

请问一下最后是如何解决的呢? 按照教,初始化的时候一直输出这个错问日志: ARouter::: InstantRun support error, com.android.tools.fd.runtime.Paths

@shifujun
Copy link
Collaborator Author

com.tencent.shadow.core.runtime.ShadowContext#getApplicationInfo
com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo
两处实现的逻辑不一致,且不应该实现两遍。
其中com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo返回的ApplicationInfo没有设置sourceDir,导致了问题#38
其中ShadowPackageManager是插件中代码通过PackageManager试图getApplicationInfo,并且传入的packageName等于插件(也等于宿主)的。我们认为这种调用实际上是试图拿到插件自己的ApplicationInfo。因此转调过来了。

请问一下最后是如何解决的呢? 按照教,初始化的时候一直输出这个错问日志: ARouter::: InstantRun support error, com.android.tools.fd.runtime.Paths

InstantRun和这个Issue应该不相关。你可以先关掉InstantRun试试。有问题的话附上修改的sample另外提issue吧。

@ehunmayh
Copy link

com.tencent.shadow.core.runtime.ShadowContext#getApplicationInfo
com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo
两处实现的逻辑不一致,且不应该实现两遍。
其中com.tencent.shadow.core.runtime.ShadowPackageManager#getApplicationInfo返回的ApplicationInfo没有设置sourceDir,导致了问题#38
其中ShadowPackageManager是插件中代码通过PackageManager试图getApplicationInfo,并且传入的packageName等于插件(也等于宿主)的。我们认为这种调用实际上是试图拿到插件自己的ApplicationInfo。因此转调过来了。

请问一下最后是如何解决的呢? 按照教,初始化的时候一直输出这个错问日志: ARouter::: InstantRun support error, com.android.tools.fd.runtime.Paths

InstantRun和这个Issue应该不相关。你可以先关掉InstantRun试试。有问题的话附上修改的sample另外提issue吧。

打断点看初始化的错误是在这里输出的catch (Exception e)中输出了 ARouter::: InstantRun support error, com.android.tools.fd.runtime.Paths:
/**
* Get instant run dex path, used to catch the branch usingApkSplits=false.
*/
private static List tryLoadInstantRunDexFile(ApplicationInfo applicationInfo) {
List instantRunSourcePaths = new ArrayList<>();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && null != applicationInfo.splitSourceDirs) {
        // add the split apk, normally for InstantRun, and newest version.
        instantRunSourcePaths.addAll(Arrays.asList(applicationInfo.splitSourceDirs));
        Log.d(Consts.TAG, "Found InstantRun support");
    } else {
        try {
            // This man is reflection from Google instant run sdk, he will tell me where the dex files go.
            Class pathsByInstantRun = Class.forName("com.android.tools.fd.runtime.Paths");
            Method getDexFileDirectory = pathsByInstantRun.getMethod("getDexFileDirectory", String.class);
            String instantRunDexPath = (String) getDexFileDirectory.invoke(null, applicationInfo.packageName);

            File instantRunFilePath = new File(instantRunDexPath);
            if (instantRunFilePath.exists() && instantRunFilePath.isDirectory()) {
                File[] dexFile = instantRunFilePath.listFiles();
                for (File file : dexFile) {
                    if (null != file && file.exists() && file.isFile() && file.getName().endsWith(".dex")) {
                        instantRunSourcePaths.add(file.getAbsolutePath());
                    }
                }
                Log.d(Consts.TAG, "Found InstantRun support");
            }

        } catch (Exception e) {
            Log.e(Consts.TAG, "InstantRun support error, " + e.getMessage());
        }
    }

    return instantRunSourcePaths;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants