Search in sources :

Example 86 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class MultiUserUtilsTest method createMockDevice.

@NotNull
private static IDevice createMockDevice(@NotNull String pmListUsersOutput, @NotNull String amCurrentUserOutput) throws Exception {
    IDevice device = mock(IDevice.class);
    when(device.getVersion()).thenReturn(new AndroidVersion(23, null));
    doAnswer(invocation -> {
        String cmd = (String) invocation.getArguments()[0];
        String answer = null;
        if (cmd.equals("pm list users")) {
            answer = pmListUsersOutput;
        } else if (cmd.equals("am get-current-user")) {
            answer = amCurrentUserOutput;
        } else {
            fail("Mock device does not support shell command: " + cmd);
        }
        byte[] bytes = answer.getBytes(Charsets.UTF_8);
        IShellOutputReceiver receiver = (IShellOutputReceiver) invocation.getArguments()[1];
        receiver.addOutput(bytes, 0, bytes.length);
        receiver.flush();
        return null;
    }).when(device).executeShellCommand(anyString(), anyObject());
    return device;
}
Also used : IShellOutputReceiver(com.android.ddmlib.IShellOutputReceiver) IDevice(com.android.ddmlib.IDevice) Matchers.anyString(org.mockito.Matchers.anyString) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class InstantRunBuilderTest method fullBuildIfAppNotRunningOnApiBelow21.

@Test
public void fullBuildIfAppNotRunningOnApiBelow21() throws Exception {
    myDumpsysPackageOutput = DUMPSYS_PACKAGE_EXISTS;
    myDeviceBuildTimetamp = "100";
    myAppInForeground = false;
    when(myDevice.getVersion()).thenReturn(new AndroidVersion(20, null));
    setUpDeviceForHotSwap();
    myBuilder.build(myTaskRunner, Collections.emptyList());
    assertEquals("gradlew -Pandroid.optional.compilation=INSTANT_DEV,FULL_APK -Pandroid.injected.coldswap.mode=MULTIAPK :app:assemble", myTaskRunner.getBuilds());
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) Test(org.junit.Test)

Example 88 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class AndroidVersionsInfoTest method withPreviewAndroidTarget.

/**
   * For preview Android target versions, the Build API should be the same as the preview
   */
@Test
public void withPreviewAndroidTarget() {
    MockPlatformTarget androidTarget = new MockPlatformTarget(PREVIEW_VERSION, 0) {

        @NonNull
        @Override
        public AndroidVersion getVersion() {
            return new AndroidVersion(PREVIEW_VERSION - 1, "TEST_CODENAME");
        }
    };
    AndroidVersionsInfo.VersionItem versionItem = myMockAndroidVersionsInfo.new VersionItem(androidTarget);
    assertEquals(PREVIEW_VERSION, versionItem.getApiLevel());
    assertEquals(PREVIEW_VERSION, versionItem.getBuildApiLevel());
}
Also used : MockPlatformTarget(com.android.sdklib.internal.androidTarget.MockPlatformTarget) AndroidVersion(com.android.sdklib.AndroidVersion) Test(org.junit.Test)

Example 89 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project kotlin by JetBrains.

the class Project method initialize.

protected void initialize() {
    // Default initialization: Use ADT/ant style project.properties file
    try {
        // Read properties file and initialize library state
        Properties properties = new Properties();
        File propFile = new File(mDir, PROJECT_PROPERTIES);
        if (propFile.exists()) {
            BufferedInputStream is = new BufferedInputStream(new FileInputStream(propFile));
            try {
                properties.load(is);
                String value = properties.getProperty(ANDROID_LIBRARY);
                mLibrary = VALUE_TRUE.equals(value);
                String proguardPath = properties.getProperty(PROGUARD_CONFIG);
                if (proguardPath != null) {
                    mProguardPath = proguardPath;
                }
                mMergeManifests = VALUE_TRUE.equals(properties.getProperty(//$NON-NLS-1$
                "manifestmerger.enabled"));
                //$NON-NLS-1$
                String target = properties.getProperty("target");
                if (target != null) {
                    int index = target.lastIndexOf('-');
                    if (index == -1) {
                        index = target.lastIndexOf(':');
                    }
                    if (index != -1) {
                        String versionString = target.substring(index + 1);
                        try {
                            mBuildSdk = Integer.parseInt(versionString);
                        } catch (NumberFormatException nufe) {
                            mClient.log(Severity.WARNING, null, "Unexpected build target format: %1$s", target);
                        }
                    }
                }
                for (int i = 1; i < 1000; i++) {
                    String key = String.format(ANDROID_LIBRARY_REFERENCE_FORMAT, i);
                    String library = properties.getProperty(key);
                    if (library == null || library.isEmpty()) {
                        // No holes in the numbering sequence is allowed
                        break;
                    }
                    File libraryDir = new File(mDir, library).getCanonicalFile();
                    if (mDirectLibraries == null) {
                        mDirectLibraries = new ArrayList<Project>();
                    }
                    // Adjust the reference dir to be a proper prefix path of the
                    // library dir
                    File libraryReferenceDir = mReferenceDir;
                    if (!libraryDir.getPath().startsWith(mReferenceDir.getPath())) {
                        // Symlinks etc might have been resolved, so do those to
                        // the reference dir as well
                        libraryReferenceDir = libraryReferenceDir.getCanonicalFile();
                        if (!libraryDir.getPath().startsWith(mReferenceDir.getPath())) {
                            File file = libraryReferenceDir;
                            while (file != null && !file.getPath().isEmpty()) {
                                if (libraryDir.getPath().startsWith(file.getPath())) {
                                    libraryReferenceDir = file;
                                    break;
                                }
                                file = file.getParentFile();
                            }
                        }
                    }
                    try {
                        Project libraryPrj = mClient.getProject(libraryDir, libraryReferenceDir);
                        mDirectLibraries.add(libraryPrj);
                        // By default, we don't report issues in inferred library projects.
                        // The driver will set report = true for those library explicitly
                        // requested.
                        libraryPrj.setReportIssues(false);
                    } catch (CircularDependencyException e) {
                        e.setProject(this);
                        e.setLocation(Location.create(propFile));
                        throw e;
                    }
                }
            } finally {
                try {
                    Closeables.close(is, true);
                } catch (IOException e) {
                // cannot happen
                }
            }
        }
    } catch (IOException ioe) {
        mClient.log(ioe, "Initializing project state");
    }
    if (mDirectLibraries != null) {
        mDirectLibraries = Collections.unmodifiableList(mDirectLibraries);
    } else {
        mDirectLibraries = Collections.emptyList();
    }
    if (isAospBuildEnvironment()) {
        if (isAospFrameworksRelatedProject(mDir)) {
            // No manifest file for this project: just init the manifest values here
            mManifestMinSdk = mManifestTargetSdk = new AndroidVersion(HIGHEST_KNOWN_API, null);
        } else if (mBuildSdk == -1) {
            // only set BuildSdk for projects other than frameworks and
            // the ones that don't have one set in project.properties.
            mBuildSdk = getClient().getHighestKnownApiLevel();
        }
    }
}
Also used : AndroidProject(com.android.builder.model.AndroidProject) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) Properties(java.util.Properties) AndroidVersion(com.android.sdklib.AndroidVersion) OutputFile(com.android.build.OutputFile) File(java.io.File) FileInputStream(java.io.FileInputStream) CircularDependencyException(com.android.tools.klint.client.api.CircularDependencyException)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)89 Test (org.junit.Test)21 NotNull (org.jetbrains.annotations.NotNull)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)12 IDevice (com.android.ddmlib.IDevice)11 Nullable (org.jetbrains.annotations.Nullable)9 MockPlatformTarget (com.android.sdklib.internal.androidTarget.MockPlatformTarget)8 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)8 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)6 Project (com.intellij.openapi.project.Project)5 Abi (com.android.sdklib.devices.Abi)4 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 OutputFile (com.android.build.OutputFile)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3