/** * Returns the complete path for <code>framework.aidl</code>, based on this SDK. * * @return the complete path as a <code>String</code>, including the filename. */ public String getPathForFrameworkAidl() { return androidTarget.getPath( IAndroidTarget.ANDROID_AIDL ); }
try version = new AndroidVersion( apiLevel ); String hashString = AndroidTargetHash.getPlatformHashString( version ); IAndroidTarget target = sdkManager.getAndroidTargetManager( progressIndicator ) .getTargetFromHashString( hashString, progressIndicator ); if ( target != null && target.getLocation() != null ) throw new InvalidSdkException( "Error AndroidVersion: " + ignore.getMessage() ); for ( IAndroidTarget t: sdkManager.getAndroidTargetManager( null ).getTargets( null ) ) if ( t.isPlatform() && apiLevel.equals( t.getVersionName() ) )
/** * Resolves the android.jar from this SDK. * * @return a <code>File</code> pointing to the android.jar file. * @throws org.apache.maven.plugin.MojoExecutionException * if the file can not be resolved. */ public File getAndroidJar() throws MojoExecutionException { final String androidJarPath = androidTarget.getPath( IAndroidTarget.ANDROID_JAR ); if ( androidJarPath == null ) { throw new MojoExecutionException( "No AndroidJar found for " + androidTarget.getLocation() ); } return new File ( androidJarPath ); }
AndroidTargetManager targetManager = sdkManager.getAndroidTargetManager( progressIndicator ); for ( IAndroidTarget target: targetManager.getTargets( progressIndicator ) ) if ( target.isPlatform() ) || target.getVersion().getApiLevel() > latestTarget.getVersion().getApiLevel() ) platformDirectory = new File ( latestTarget.getLocation() ); platformDirectory = new File( androidTarget.getLocation() );
private String getMainLocaleViaProperties(Device device) { Optional<String> locale = Optional.empty(); int apiLevel = device.getVersion().getApiLevel(); if (apiLevel < Versions.ANDROID_M_API_VERSION) { Optional<String> language = device.getProperty(LEGACY_LANGUAGE_PROPERTY); Optional<String> region = device.getProperty(LEGACY_REGION_PROPERTY); if (language.isPresent() && region.isPresent()) { locale = Optional.of(language.get() + "-" + region.get()); } } else { locale = device.getProperty(LOCALE_PROPERTY_SYS); if (!locale.isPresent()) { locale = device.getProperty(LOCALE_PROPERTY_PRODUCT); } } return locale.orElseGet( () -> { System.err.println("Warning: Can't detect device locale, will use 'en-US'."); return "en-US"; }); }
private boolean isPostN() { final AndroidVersion hash = AndroidTargetHash.getVersionFromHash(compileSdkVersion); return hash != null && hash.getApiLevel() >= 24; } }
@Override public void installApks(ImmutableList<Path> apks, InstallOptions installOptions) { ImmutableList<File> apkFiles = apks.stream().map(Path::toFile).collect(toImmutableList()); try { if (getVersion() .isGreaterOrEqualThan(AndroidVersion.ALLOW_SPLIT_APK_INSTALLATION.getApiLevel())) { device.installPackages( apkFiles, installOptions.getAllowReinstall(), installOptions.getAllowDowngrade() ? ImmutableList.of("-d") : ImmutableList.of(), installOptions.getTimeout().toMillis(), TimeUnit.MILLISECONDS); } else { device.installPackage( Iterables.getOnlyElement(apkFiles).toString(), installOptions.getAllowReinstall(), installOptions.getAllowDowngrade() ? "-d" : null); } } catch (InstallException e) { throw InstallationException.builder() .withCause(e) .withMessage("Installation of the app failed.") .build(); } } }
FakeDevice( String serialNumber, DeviceState state, int sdkVersion, ImmutableList<String> abis, int density, ImmutableList<String> features, ImmutableMap<String, String> properties) { this.state = state; this.androidVersion = new AndroidVersion(sdkVersion); this.abis = abis; this.density = density; this.serialNumber = serialNumber; this.properties = properties; this.features = features; }
BuildToolInfo buildToolInfo = sdkManager.getBuildToolInfo( Revision.parseRevision( buildToolsVersion ), progressIndicator ); if ( buildToolInfo != null ) BuildToolInfo buildToolInfo = androidTarget.getBuildToolInfo(); if ( buildToolInfo != null ) BuildToolInfo latestBuildToolInfo = sdkManager.getLatestBuildTool( progressIndicator, true ); if ( latestBuildToolInfo == null )
/** * Get the path for build-tools lib directory * @return */ public String getBuildToolsLibDirectoryPath() { File buildToolsLib = new File( getBuildToolInfo().getLocation(), "lib" ); if ( buildToolsLib.exists() ) { return buildToolsLib.getAbsolutePath(); } throw new InvalidSdkException( "Cannot find " + buildToolsLib ); }
public void assertThatBuildToolsVersionIsAtLeast( String version, String feature ) throws InvalidSdkException, NumberFormatException { if ( getBuildToolInfo().getRevision(). compareTo( Revision.parseRevision( version ) ) < 0 ) { throw new InvalidSdkException( "Version of build tools must be at least " + version + " for " + feature + " to work" ); } }
private String getPathForBuildTool( BuildToolInfo.PathId pathId ) { return getBuildToolInfo().getPath( pathId ); }
/** * Compares this version with the specified API and returns true if this version * is greater or equal than the requested API -- that is the current version is a * suitable min-api-level for the argument API. */ public boolean isGreaterOrEqualThan(int api) { return compareTo(api, null /*codename*/) >= 0; }
/** * Gets the path/unique id for the platform of the given {@link AndroidVersion}. */ public static String getPlatformPath(AndroidVersion version) { return SdkConstants.FD_PLATFORMS + RepoPackage.PATH_SEPARATOR + "android-" + version.getApiString(); }
int deviceSdkVersion = device.getVersion().getApiLevel(); checkState(deviceSdkVersion > 1, "Error retrieving device SDK version. Please try again."); int deviceDensity = device.getDensity();
@Test public void allowDowngrade_preL() throws Exception { when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.KITKAT)); DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice); ddmlibDevice.installApks( ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(true).build()); verify(mockDevice).installPackage(eq(APK_PATH.toString()), anyBoolean(), eq("-d")); }
/** * Get the path for mainDexClasses.rules * @return */ public String getMainDexClassesRulesPath() { File mainDexClassesRules = new File( getBuildToolInfo().getLocation(), "mainDexClasses.rules" ); if ( mainDexClassesRules.exists() ) { return mainDexClassesRules.getAbsolutePath(); } throw new InvalidSdkException( "Cannot find " + mainDexClassesRules ); }
/** * Gets the path/unique id for the sources of the given {@link AndroidVersion}. */ public static String getSourcesPath(AndroidVersion version) { return SdkConstants.FD_PKG_SOURCES + RepoPackage.PATH_SEPARATOR + "android-" + version.getApiString(); }
@Test public void doesNotAllowDowngrade() throws Exception { when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.KITKAT)); DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice); ddmlibDevice.installApks( ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(false).build()); // -d should *not* be passed as extra arg. verify(mockDevice).installPackage(eq(APK_PATH.toString()), anyBoolean(), (String) isNull()); }
@SuppressWarnings("unchecked") @Test public void allowDowngrade_postL() throws Exception { when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.LOLLIPOP)); DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice); ddmlibDevice.installApks( ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(true).build()); ArgumentCaptor<List<String>> extraArgsCaptor = ArgumentCaptor.forClass((Class) List.class); verify(mockDevice) .installPackages( eq(ImmutableList.of(APK_PATH.toFile())), anyBoolean(), extraArgsCaptor.capture(), anyLong(), any(TimeUnit.class)); assertThat(extraArgsCaptor.getValue()).contains("-d"); } }