java.lang.NoSuchMethodException:generatePackageInfo

时间:2012-06-08 03:23:38

标签: android reflection apk sign

有没有人使用 java反射在Android源代码中使用隐藏类 PackageParser

我可以以反射方式获取此类及其方法collectCertificates(),但我继续使用其方法 generatePackageInfo()获取NoSuchMethodException。

我想知道以下句子是否会导致这个问题,因为我对 int []的使用不太确定.class

partypesGeneratePackageInfo [1] = int [] .class;

这是我的代码:

    private PackageInfo parsePackage(String archiveFilePath, int flags)
        throws Exception, Exception {
    // get class:PackageParser
    Class clsPackageParser = Class
            .forName("android.content.pm.PackageParser");

            ......      

    // get method:collectCertificates
    Class partypesCollectCertificates[] = new Class[2];
    partypesCollectCertificates[0] = clsPackage;
    partypesCollectCertificates[1] = int.class;
    Method methCollectCertificates = clsPackageParser.getMethod(
            "collectCertificates", partypesCollectCertificates);

    // invoke method:collectCertificates
    Object arglistMethCollectCertificates[] = new Object[2];
    arglistMethCollectCertificates[0] = objPackage;
    arglistMethCollectCertificates[1] = flags;
    methCollectCertificates.invoke(objPackageParser,
            arglistMethCollectCertificates);

    // get method:generatePackageInfo
    Class partypesGeneratePackageInfo[] = new Class[3];
    partypesGeneratePackageInfo[0] = clsPackage;
    partypesGeneratePackageInfo[1] = int[].class;
    partypesGeneratePackageInfo[2] = int.class;
    Method methGeneratePackageInfo = clsPackageParser.getMethod(
            "generatePackageInfo", partypesGeneratePackageInfo);

    ......
}

1 个答案:

答案 0 :(得分:0)

我可以看到,generatePackageInfo的声明是:

public static PackageInfo generatePackageInfo(PackageParser.Package p,
        int gids[], int flags, long firstInstallTime, long lastUpdateTime) {

这是5个参数:PackageParser.Package.class, int[].class, int.class, long.class, long.class

由于这不是一个公开的API,很可能是参数的数量从版本变为版本。