@Override protected AndroidManifest getAppManifest(Config config) { String appRoot = "src/main/"; String manifestPath = appRoot + "AndroidManifest.xml"; String resDir = appRoot + "res"; String assetsDir = appRoot + "assets"; //return new AndroidManifest(Fs.fileFromPath("src/main/AndroidManifest.xml"), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) { return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) { @Override public List<ResourcePath> getIncludedResourcePaths() { List<ResourcePath> paths = super.getIncludedResourcePaths(); paths.add(new ResourcePath(getRClass(), Fs.fileFromPath("src/main/res"), getAssetsDirectory())); paths.add(new ResourcePath(getRClass(), Fs.fileFromPath("src/test/res"), getAssetsDirectory())); return paths; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { final String manifestPath = PathResolver.resolveAndroidManifestPath(); final String resourcesPath = PathResolver.resolveResPath(); final String assetsPath = PathResolver.resolveAssetsPath(); AndroidManifest manifest = new AndroidManifest( Fs.fileFromPath(manifestPath), Fs.fileFromPath(resourcesPath), Fs.fileFromPath(assetsPath)) { @Override public int getTargetSdkVersion() { return TARGET_SDK_VERSION; } @Override public int getMinSdkVersion() { return MIN_SDK_VERSION; } }; return manifest; }
@Test public void shouldMatchPermissions() { // Initialize: configure test for current app configuration FsFile mergedManifestFile; Object[] expectedPermissions; if (BuildConfig.DEBUG) { mergedManifestFile = Fs.fileFromPath(MERGED_DEBUG_MANIFEST_FILE); expectedPermissions = EXPECTED_DEBUG_PERMISSIONS; } else { mergedManifestFile = Fs.fileFromPath(MERGED_RELEASE_MANIFEST_FILE); expectedPermissions = EXPECTED_RELEASE_PERMISSIONS; } // Run: Creates a Robolectric configuration using specified manifest file AndroidManifest manifest = new AndroidManifest(mergedManifestFile, null, null); // Check: manifest file should contain only expected permissions assertThat(manifest.getUsedPermissions()) .containsExactly(expectedPermissions); }
@Override protected Properties getConfigProperties() { Properties configProperties = super.getConfigProperties(); if (configProperties == null) { configProperties = new Properties(); } String manifestPath = "src/test/AndroidManifest.xml"; FsFile manifestFile = Fs.newFile(new File(manifestPath)); if (manifestFile.exists()) { configProperties.put("manifest", manifestPath); } else { configProperties.put("manifest", "LikeOrmExample/" + manifestPath); } configProperties.put("emulateSdk", "16"); return configProperties; }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = System.getProperty("android.manifest"); if (config.manifest().equals(Config.DEFAULT) && manifestProperty != null) { String resProperty = System.getProperty("android.resources"); String assetsProperty = System.getProperty("android.assets"); AndroidManifest androidManifest = new AndroidManifest( Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty), Fs.fileFromPath(assetsProperty)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; androidManifest.setPackageName("zenproject.meditation.android"); return androidManifest; } return super.getAppManifest(config); }
@Override protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) { return new AndroidManifest( Fs.fileFromPath("src/main/AndroidManifest.xml"), Fs.fileFromPath("src/main/res"), Fs.fileFromPath("src/main/assets")) { @Override public int getTargetSdkVersion() { return 18; } @Override public String getThemeRef(Class<? extends Activity> activityClass) { return "@android:style/Theme.Holo.Light.NoActionBar"; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { String appRoot = "../app/src/main/"; String manifestPath = appRoot + "AndroidManifest.xml"; String resDir = appRoot + "res"; String assetsDir = appRoot + "assets"; AndroidManifest manifest = createAppManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)); // If you change the package - don't forget to change the build.gradle and the AndroidManifest.xml manifest.setPackageName("com.soagrowers.android"); // Robolectric is already going to look in the 'app' dir ... // so no need to add to package name return manifest; }
@Override protected AndroidManifest getAppManifest(Config config) { final String manifestPath = PathResolver.resolveAndroidManifestPath(); final String resourcesPath = PathResolver.resolveResPath(); final String assetsPath = PathResolver.resolveAssetsPath(); AndroidManifest manifest = new AndroidManifest( Fs.fileFromPath(manifestPath), Fs.fileFromPath(resourcesPath), Fs.fileFromPath(assetsPath)) { @Override public int getTargetSdkVersion() { return TARGET_SDK_VERSION; } @Override public int getMinSdkVersion() { return MIN_SDK_VERSION; } }; manifest.setPackageName("pl.dawidgdanski.bakery"); return manifest; }
@Override public AndroidManifest getAppManifest(Config config) { return new AndroidManifest( Fs.fileFromPath(MANIFEST_PROPERTY), Fs.fileFromPath(RES_PROPERTY) ) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } @Override public String getThemeRef(Class<? extends Activity> activityClass) { return "@style/AppTheme"; // Needs to define default theme } }; }
@Override protected AndroidManifest getAppManifest(Config config) { String path = "src/main"; if (!new File(path).exists()) { path = "app/" + path; } final String manifestProperty = path + "/AndroidManifest.xml"; final String resProperty = path + "/res"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) { @Override public int getTargetSdkVersion() { return ROBOLECTRIC_SDK_VERSION; } @Override public String getThemeRef(Class<? extends Activity> activityClass) { return ROBOLECTRIC_THEME; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { //String appRoot = "D:\\TmpCodingProjects\\TripComputer\\app\\src\\main\\"; String appRoot = "../app/src/main/"; String manifestPath = appRoot + "AndroidManifest.xml"; String resDir = appRoot + "res"; String assetsDir = appRoot + "assets"; AndroidManifest manifest = createAppManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)); // If you change the package - don't forget to change the build.gradle and the AndroidManifest.xml manifest.setPackageName("com.soagrowers.android"); // Robolectric is already going to look in the 'app' dir ... // so no need to add to package name return manifest; }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestPath = APP_ROOT_DIRECTORY + ANDROID_MANIFEST_FILE_NAME; String resDir = APP_ROOT_DIRECTORY + RES_DIR; String assetsDir = APP_ROOT_DIRECTORY + ASSETS_DIR; AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; return manifest; }
/** * Test to check if libraries are adding extra permissions to the app manifest. */ @Test public void shouldMatchPermissions() { AndroidManifest manifest = new AndroidManifest( Fs.fileFromPath(MERGED_MANIFEST), null, null ); assertThat(new HashSet<>(manifest.getUsedPermissions())). containsExactly((Object[]) EXPECTED_PERMISSIONS); }
@Override protected AndroidManifest getAppManifest(Config config) { String basePath = new File(".").getAbsolutePath(); String manifest = basePath + "/src/main/AndroidManifest.xml"; String res = basePath + String.format("/build/intermediates/res/merged/%1$s/%2$s", BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE); String asset = basePath + "/src/test/assets"; return new AndroidManifest(Fs.fileFromPath(manifest), Fs.fileFromPath(res), Fs.fileFromPath(asset)); }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = "../rosie/src/test/AndroidManifest.xml"; String resProperty = "../rosie/src/main/res"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; }
@Test public void testPermissions() { String MERGED_MANIFEST = "build/intermediates/manifests/full/debug/AndroidManifest.xml"; String EXPECTED_PERMISSIONS = "android.permission.INTERNET"; AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(MERGED_MANIFEST), null, null); LogUtil.print(manifest.getUsedPermissions().toString()); assertThat(manifest.getUsedPermissions()).contains(EXPECTED_PERMISSIONS); }
@Override protected AndroidManifest getAppManifest(Config config) { String buildVariant = (BuildConfig.FLAVOR.isEmpty() ? "" : BuildConfig.FLAVOR + "/") + BuildConfig.BUILD_TYPE; return new AndroidManifest( Fs.fileFromPath("src/test/AndroidManifest.xml"), Fs.fileFromPath("build/intermediates/res/" + buildVariant), Fs.fileFromPath("src/test/assets") ); }
private static AndroidManifest getAndroidManifest() { return new AndroidManifest(Fs.fileFromPath(MANIFEST), Fs.fileFromPath(RESOURCES), Fs.fileFromPath(ASSETS)) { @Override public int getTargetSdkVersion() { return TARGET_SDK_VERSION; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { String appRoot = "./app/src/main/"; String manifestPath = appRoot + "AndroidManifest.xml"; String resDir = appRoot + "res"; String assetsDir = appRoot + "assets"; AndroidManifest manifest = createAppManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)); manifest.setPackageName("com.nhpatt.myconference"); return manifest; }
@Override protected AndroidManifest getAppManifest(Config config) { String myAppPath = ClientApp.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String manifestPath = myAppPath + "../../../../src/main/AndroidManifest.xml"; String resPath = myAppPath + "../../../../src/main/res"; String assetPath = myAppPath + "../../../../src/main/assets"; return createAppManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resPath), Fs.fileFromPath(assetPath)); }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = "../nox/src/test/AndroidManifest.xml"; String resProperty = "../nox/src/main/res"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { String buckManifest = System.getProperty(ROBOLECTRIC_MANIFEST); String buckResourcesProperty = System.getProperty(ROBOLECTRIC_RESOURCE_DIRECTORIES); if (buckManifest != null && buckResourcesProperty != null) { final List<String> buckResources = Arrays.asList(buckResourcesProperty.split(File.pathSeparator)); final FsFile res = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); final FsFile assets = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); final FsFile manifest = Fs.fileFromPath(buckManifest); return new AndroidManifest(manifest, res, assets, config.packageName()) { @Override public List<ResourcePath> getIncludedResourcePaths() { Collection<ResourcePath> resourcePaths = new LinkedHashSet<>(); resourcePaths.add(super.getResourcePath()); ListIterator<String> it = buckResources.listIterator(buckResources.size()); while (it.hasPrevious()) { resourcePaths.add(new ResourcePath( getRClass(), getPackageName(), Fs.fileFromPath(it.previous()), getAssetsDirectory())); } return new ArrayList<>(resourcePaths); } }; } else { return null; } }
protected AndroidManifest getAppManifest(Config config) { if (config.manifest().equals(Config.NONE)) { return null; } String manifestProperty = System.getProperty("android.manifest"); String resourcesProperty = System.getProperty("android.resources"); String assetsProperty = System.getProperty("android.assets"); FsFile fsFile = getBaseDir(); FsFile manifestFile; FsFile resDir; FsFile assetsDir; boolean defaultManifest = config.manifest().equals(Config.DEFAULT); if (defaultManifest && manifestProperty != null) { manifestFile = Fs.fileFromPath(manifestProperty); resDir = Fs.fileFromPath(resourcesProperty); assetsDir = Fs.fileFromPath(assetsProperty); } else { manifestFile = fsFile.join(defaultManifest ? "AndroidManifest.xml" : config.manifest()); resDir = manifestFile.getParent().join(config.resourceDir()); assetsDir = manifestFile.getParent().join("assets"); } synchronized (envHolder) { AndroidManifest appManifest; appManifest = envHolder.appManifestsByFile.get(manifestFile); if (appManifest == null) { long startTime = System.currentTimeMillis(); appManifest = createAppManifest(manifestFile, resDir, assetsDir); if (DocumentLoader.DEBUG_PERF) System.out.println(String.format("%4dms spent in %s", System.currentTimeMillis() - startTime, manifestFile)); envHolder.appManifestsByFile.put(manifestFile, appManifest); } return appManifest; } }
public PackageResourceLoader createSystemResourceLoader(MavenCentral mavenCentral, RobolectricTestRunner robolectricTestRunner) { URL url = mavenCentral.getLocalArtifactUrl(robolectricTestRunner, sdkConfig.getSystemResourceDependency()); Fs systemResFs = Fs.fromJar(url); ResourceExtractor resourceExtractor = new ResourceExtractor(getRobolectricClassLoader()); ResourcePath resourcePath = new ResourcePath(resourceExtractor.getProcessedRFile(), resourceExtractor.getPackageName(), systemResFs.join("res"), systemResFs.join("assets")); return new PackageResourceLoader(resourcePath, resourceExtractor); }
public static XmlResourceParser getXmlResourceParser(String file, String packageName, ResourceIndex resourceIndex) { FsFile fsFile = Fs.fileFromPath(file); Document document = new XmlFileLoader(null, "xml").parse(fsFile); if (document == null) { throw new Resources.NotFoundException("couldn't find resource " + fsFile.getPath()); } return new XmlFileBuilder().getXml(document, fsFile.getPath(), packageName, resourceIndex); }
protected File getNativeLibraryPath() { String tempPath = System.getProperty("java.io.tmpdir"); if (tempPath == null) { throw new IllegalStateException("Java temporary directory is not defined (java.io.tmpdir)"); } return new File(Fs.fileFromPath(tempPath).join("robolectric-libs", getLibName()).getPath()); }
private AndroidManifest newConfigWith(String packageName, String contents) throws IOException { File f = temporaryFolder.newFile("whatever.xml", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " package=\"" + packageName + "\">\n" + " " + contents + "\n" + "</manifest>\n"); return new AndroidManifest(Fs.newFile(f), null, null); }
public AndroidManifest newConfigWith(String usesSdkAttrs) throws IOException { File f = temporaryFolder.newFile("whatever.xml", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " package=\"org.robolectric\">\n" + " <uses-sdk " + usesSdkAttrs + "/>\n" + "</manifest>\n"); return new AndroidManifest(Fs.newFile(f), null, null); }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = System.getProperty("android.manifest"); if (config.manifest().equals(Config.DEFAULT) && manifestProperty != null) { String resProperty = System.getProperty("android.resources"); String assetsProperty = System.getProperty("android.assets"); return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty), Fs.fileFromPath(assetsProperty)); } return super.getAppManifest(config); }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = "../app/src/main/AndroidManifest.xml"; String resProperty = "../app/src/main/res"; String assetsProperty = "../app/src/main/assets"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty), Fs.fileFromPath(assetsProperty)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = System.getProperty("android.manifest"); if (config.manifest().equals(Config.DEFAULT) && manifestProperty != null) { String resProperty = System.getProperty("android.resources"); String assetsProperty = System.getProperty("android.assets"); return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty), Fs.fileFromPath(assetsProperty)); } AndroidManifest appManifest = super.getAppManifest(config); return appManifest; }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = "src/main/AndroidManifest.xml"; String resProperty = "src/main/res"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { return new AndroidManifest( Fs.fileFromPath("src/main/AndroidManifest.xml"), Fs.fileFromPath("src/main/res"), Fs.fileFromPath("src/main/assets")) { @Override public int getTargetSdkVersion() { return 18; } }; }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = "src/main/AndroidManifest.xml"; String resProperty = "src/main/res"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) { @Override public int getTargetSdkVersion() { return 18; } }; }
@Test public void shouldMatchPermissions() { AndroidManifest manifest = new AndroidManifest( Fs.fileFromPath(MERGED_MANIFEST), null, null ); assertThat(new HashSet<>(manifest.getUsedPermissions())). containsOnly(EXPECTED_PERMISSIONS); }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestPath = "AndroidManifest.xml"; String resPath = "src/main/res/"; String assets = "src/main/assets/"; return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resPath), Fs.fileFromPath(assets)) { @Override public int getTargetSdkVersion() { return 18; } }; }