@Test public void getPackageName() throws Exception { Assert.assertEquals("net.yui", resources.getPackageName()); }
public String getPackageName() { if (!TextUtils.isEmpty(mPackageName)) { return mPackageName; } String manifestPath = null; List<String> manifestPaths = Arrays.asList( "build/intermediates/manifests/aapt/debug/AndroidManifest.xml", "build/intermediates/manifests/aapt/release/AndroidManifest.xml", "build/intermediates/manifests/aapt/full/release/AndroidManifest.xml", "build/intermediates/manifests/full/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/release/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/release/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/AndroidManifest.xml", "build/intermediates/library_manifest/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml" ); manifestPath = findExistPath(manifestPaths); if (TextUtils.isEmpty(manifestPath)) { manifestPath = findPath("AndroidManifest.xml", "build/intermediates"); } if (TextUtils.isEmpty(manifestPath)) { throw new RuntimeException("没有找到AndroidManifest.xml"); } FileReader reader = new FileReader(); if (new File(manifestPath).exists()) { String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); return mPackageName = packageName; } else { manifestPath = "build/intermediates/manifest/androidTest/debug/AndroidManifest.xml"; String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); packageName = packageName.substring(0, packageName.length() - ".test".length()); return mPackageName = packageName; } }
ShadowResources { public String getPackageName() { if (!TextUtils.isEmpty(mPackageName)) { return mPackageName; } String manifestPath = null; List<String> manifestPaths = Arrays.asList( "build/intermediates/manifests/aapt/debug/AndroidManifest.xml", "build/intermediates/manifests/aapt/release/AndroidManifest.xml", "build/intermediates/manifests/aapt/full/release/AndroidManifest.xml", "build/intermediates/manifests/full/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/release/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/release/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/AndroidManifest.xml", "build/intermediates/library_manifest/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml" ); manifestPath = findExistPath(manifestPaths); if (TextUtils.isEmpty(manifestPath)) { manifestPath = findPath("AndroidManifest.xml", "build/intermediates"); } if (TextUtils.isEmpty(manifestPath)) { throw new RuntimeException("没有找到AndroidManifest.xml"); } FileReader reader = new FileReader(); if (new File(manifestPath).exists()) { String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); return mPackageName = packageName; } else { manifestPath = "build/intermediates/manifest/androidTest/debug/AndroidManifest.xml"; String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); packageName = packageName.substring(0, packageName.length() - ".test".length()); return mPackageName = packageName; } } }
ShadowResources { public String getPackageName() { if (!TextUtils.isEmpty(mPackageName)) { return mPackageName; } String manifestPath = null; List<String> manifestPaths = Arrays.asList( "build/intermediates/manifests/aapt/debug/AndroidManifest.xml", "build/intermediates/manifests/aapt/release/AndroidManifest.xml", "build/intermediates/manifests/aapt/full/release/AndroidManifest.xml", "build/intermediates/manifests/full/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/release/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/release/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/AndroidManifest.xml", "build/intermediates/library_manifest/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml" ); manifestPath = findExistPath(manifestPaths); if (TextUtils.isEmpty(manifestPath)) { manifestPath = findPath("AndroidManifest.xml", "build/intermediates"); } if (TextUtils.isEmpty(manifestPath)) { throw new RuntimeException("没有找到AndroidManifest.xml"); } FileReader reader = new FileReader(); if (new File(manifestPath).exists()) { String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); return mPackageName = packageName; } else { manifestPath = "build/intermediates/manifest/androidTest/debug/AndroidManifest.xml"; String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); packageName = packageName.substring(0, packageName.length() - ".test".length()); return mPackageName = packageName; } } ShadowResources(); }
ShadowResources { public String getPackageName() { if (!TextUtils.isEmpty(mPackageName)) { return mPackageName; } String manifestPath = null; List<String> manifestPaths = Arrays.asList( "build/intermediates/manifests/aapt/debug/AndroidManifest.xml", "build/intermediates/manifests/aapt/release/AndroidManifest.xml", "build/intermediates/manifests/aapt/full/release/AndroidManifest.xml", "build/intermediates/manifests/full/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/release/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/release/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/AndroidManifest.xml", "build/intermediates/library_manifest/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml" ); manifestPath = findExistPath(manifestPaths); if (TextUtils.isEmpty(manifestPath)) { manifestPath = findPath("AndroidManifest.xml", "build/intermediates"); } if (TextUtils.isEmpty(manifestPath)) { throw new RuntimeException("没有找到AndroidManifest.xml"); } FileReader reader = new FileReader(); if (new File(manifestPath).exists()) { String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); return mPackageName = packageName; } else { manifestPath = "build/intermediates/manifest/androidTest/debug/AndroidManifest.xml"; String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); packageName = packageName.substring(0, packageName.length() - ".test".length()); return mPackageName = packageName; } } ShadowResources(); int getColor(@ColorRes int id); int getColor(@ColorRes int id, @Nullable Resources.Theme theme); String getString(@StringRes int id); @NonNull String[] getStringArray(@ArrayRes int id); @NonNull int[] getIntArray(@ArrayRes int id); String getPackageName(); }
ShadowResources { public String getPackageName() { if (!TextUtils.isEmpty(mPackageName)) { return mPackageName; } String manifestPath = null; List<String> manifestPaths = Arrays.asList( "build/intermediates/manifests/aapt/debug/AndroidManifest.xml", "build/intermediates/manifests/aapt/release/AndroidManifest.xml", "build/intermediates/manifests/aapt/full/release/AndroidManifest.xml", "build/intermediates/manifests/full/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/release/processDebugManifest/aapt/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/release/processDebugManifest/merged/AndroidManifest.xml", "build/intermediates/merged_manifests/debug/AndroidManifest.xml", "build/intermediates/library_manifest/debug/AndroidManifest.xml", "build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml" ); manifestPath = findExistPath(manifestPaths); if (TextUtils.isEmpty(manifestPath)) { manifestPath = findPath("AndroidManifest.xml", "build/intermediates"); } if (TextUtils.isEmpty(manifestPath)) { throw new RuntimeException("没有找到AndroidManifest.xml"); } FileReader reader = new FileReader(); if (new File(manifestPath).exists()) { String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); return mPackageName = packageName; } else { manifestPath = "build/intermediates/manifest/androidTest/debug/AndroidManifest.xml"; String manifest = reader.readString(manifestPath); Element body = Jsoup.parse(manifest).body(); String packageName = body.childNode(0).attr("package"); packageName = packageName.substring(0, packageName.length() - ".test".length()); return mPackageName = packageName; } } ShadowResources(); int getColor(@ColorRes int id); int getColor(@ColorRes int id, @Nullable Resources.Theme theme); String getString(@StringRes int id); @NonNull String[] getStringArray(@ArrayRes int id); @NonNull int[] getIntArray(@ArrayRes int id); String getPackageName();  }