com.android.sdklib.IAndroidTarget Java Examples

The following examples show how to use com.android.sdklib.IAndroidTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlatformPackage.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * A platform package is typically installed in SDK/platforms/android-"version".
 * However if we can find a different directory under SDK/platform that already
 * has this platform version installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {

    // First find if this platform is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (target.isPlatform() && target.getVersion().equals(mVersion)) {
            return new File(target.getLocation());
        }
    }

    File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);
    File folder = new File(platforms,
            String.format("android-%s", getAndroidVersion().getApiString())); //$NON-NLS-1$

    return folder;
}
 
Example #2
Source File: LocalSdk.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the targets (platforms & addons) that are available in the SDK.
 * The target list is created on demand the first time then cached.
 * It will not refreshed unless {@link #clearLocalPkg} is called to clear platforms
 * and/or add-ons.
 * <p/>
 * The array can be empty but not null.
 */
@NonNull
public IAndroidTarget[] getTargets() {
    synchronized (mLocalPackages) {
        if (mCachedTargets == null) {
            List<IAndroidTarget> result = Lists.newArrayList();
            LocalPkgInfo[] pkgsInfos = getPkgsInfos(EnumSet.of(PkgType.PKG_PLATFORM,
                    PkgType.PKG_ADDON));
            for (LocalPkgInfo info : pkgsInfos) {
                assert info instanceof LocalPlatformPkgInfo;
                IAndroidTarget target = ((LocalPlatformPkgInfo) info).getAndroidTarget();
                if (target != null) {
                    result.add(target);
                }
            }
            mCachedTargets = result;
        }
        return mCachedTargets.toArray(new IAndroidTarget[mCachedTargets.size()]);
    }
}
 
Example #3
Source File: SamplePackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private SamplePackage(IAndroidTarget target, Properties props) {
    super(  null,                                   //source
            props,                                  //properties
            0,                                      //revision will be taken from props
            null,                                   //license
            null,                                   //description
            null,                                   //descUrl
            target.getPath(IAndroidTarget.SAMPLES)  //archiveOsPath
            );

    mVersion = target.getVersion();

    mMinApiLevel = getPropertyInt(props, PkgProps.SAMPLE_MIN_API_LEVEL,
            MIN_API_LEVEL_NOT_SPECIFIED);

    mPkgDesc = setDescriptions(PkgDesc.Builder
            .newSample(mVersion, (MajorRevision) getRevision(), getMinToolsRevision()))
            .create();
}
 
Example #4
Source File: SamplePackage.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private SamplePackage(IAndroidTarget target, Properties props) {
    super(  null,                                   //source
            props,                                  //properties
            0,                                      //revision will be taken from props
            null,                                   //license
            null,                                   //description
            null,                                   //descUrl
            target.getPath(IAndroidTarget.SAMPLES)  //archiveOsPath
            );

    mVersion = target.getVersion();

    mMinApiLevel = getPropertyInt(props, PkgProps.SAMPLE_MIN_API_LEVEL,
                                         MIN_API_LEVEL_NOT_SPECIFIED);

    mPkgDesc = PkgDesc.Builder
            .newSample(mVersion,
                      (MajorRevision) getRevision(),
                      getMinToolsRevision())
            .setDescriptions(this)
            .create();
}
 
Example #5
Source File: LocalAddonPkgInfo.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts a string representation of an hexadecimal ID into an int.
 * @param value the string to convert.
 * @return the int value, or {@link IAndroidTarget#NO_USB_ID} if the conversion failed.
 */
private int convertId(@Nullable String value) {
    if (value != null && !value.isEmpty()) {
        if (PATTERN_USB_IDS.matcher(value).matches()) {
            String v = value.substring(2);
            try {
                return Integer.parseInt(v, 16);
            } catch (NumberFormatException e) {
                // this shouldn't happen since we check the pattern above, but this is safer.
                // the method will return 0 below.
            }
        }
    }

    return IAndroidTarget.NO_USB_ID;
}
 
Example #6
Source File: PlatformTarget.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = mVersion.compareTo(target.getVersion());

    // only if the version are the same do we care about add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform() == false) {
            return -1;
        }
    }

    return versionDiff;
}
 
Example #7
Source File: PlatformPackage.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting(visibility=Visibility.PRIVATE)
protected PlatformPackage(@Nullable SdkSource source,
                          @NonNull IAndroidTarget target,
                          @Nullable Properties props) {
    super(  source,                     //source
            props,                      //properties
            target.getRevision(),       //revision
            null,                       //license
            target.getDescription(),    //description
            null,                       //descUrl
            target.getLocation()        //archiveOsPath
            );

    mVersion = target.getVersion();
    mVersionName  = target.getVersionName();
    mLayoutlibVersion = new LayoutlibVersionMixin(props);
    mIncludedAbi = props == null ? null : props.getProperty(PkgProps.PLATFORM_INCLUDED_ABI);

    mPkgDesc = PkgDesc.Builder
            .newPlatform(mVersion,
                         (MajorRevision) getRevision(),
                         getMinToolsRevision())
            .setDescriptions(this)
            .create();
}
 
Example #8
Source File: PlatformTarget.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public File getDefaultSkin() {
    // only one skin? easy.
    if (mSkins.length == 1) {
        return mSkins[0];
    }

    // look for the skin name in the platform props
    String skinName = mProperties.get(SdkConstants.PROP_SDK_DEFAULT_SKIN);
    if (skinName == null) {
        // otherwise try to find a good default.
        if (mVersion.getApiLevel() >= 4) {
            // at this time, this is the default skin for all older platforms that had 2+ skins.
            skinName = "WVGA800";                                       //$NON-NLS-1$
        } else {
            skinName = "HVGA"; // this is for 1.5 and earlier.          //$NON-NLS-1$
        }
    }

    return new File(getFile(IAndroidTarget.SKINS), skinName);
}
 
Example #9
Source File: PlatformPackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@VisibleForTesting(visibility=Visibility.PRIVATE)
protected PlatformPackage(@Nullable SdkSource source,
                          @NonNull IAndroidTarget target,
                          @Nullable Properties props) {
    super(  source,                     //source
            props,                      //properties
            target.getRevision(),       //revision
            null,                       //license
            target.getDescription(),    //description
            null,                       //descUrl
            target.getLocation()        //archiveOsPath
            );

    mVersion = target.getVersion();
    mVersionName  = target.getVersionName();
    mLayoutlibVersion = new LayoutlibVersionMixin(props);
    mIncludedAbi = props == null ? null : props.getProperty(PkgProps.PLATFORM_INCLUDED_ABI);

    mPkgDesc = setDescriptions(PkgDesc.Builder
            .newPlatform(mVersion, (MajorRevision) getRevision(), getMinToolsRevision()))
            .create();
}
 
Example #10
Source File: PlatformPackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * A platform package is typically installed in SDK/platforms/android-"version".
 * However if we can find a different directory under SDK/platform that already
 * has this platform version installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {

    // First find if this platform is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (target.isPlatform() && target.getVersion().equals(mVersion)) {
            return new File(target.getLocation());
        }
    }

    File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);
    File folder = new File(platforms,
            String.format("android-%s", getAndroidVersion().getApiString())); //$NON-NLS-1$

    return folder;
}
 
Example #11
Source File: PlatformTarget.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int compareTo(IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = mVersion.compareTo(target.getVersion());

    // only if the version are the same do we care about add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform() == false) {
            return -1;
        }
    }

    return versionDiff;
}
 
Example #12
Source File: LintDetectorTest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public IAndroidTarget getCompileTarget(@NonNull Project project) {
    IAndroidTarget compileTarget = super.getCompileTarget(project);
    if (compileTarget == null) {
        IAndroidTarget[] targets = getTargets();
        for (int i = targets.length - 1; i >= 0; i--) {
            IAndroidTarget target = targets[i];
            if (target.isPlatform()) {
                return target;
            }
        }
    }

    return compileTarget;
}
 
Example #13
Source File: PlatformLoader.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public TargetInfo getTargetInfo(@NonNull String targetHash,
        @NonNull FullRevision buildToolRevision, @NonNull ILogger logger) {
    init(logger);

    IAndroidTarget androidTarget = new FakeAndroidTarget(mTreeLocation.getPath(), targetHash);

    File hostTools = getHostToolsFolder();

    BuildToolInfo buildToolInfo = new BuildToolInfo(
            buildToolRevision,
            mTreeLocation,
            new File(hostTools, FN_AAPT),
            new File(hostTools, FN_AIDL),
            new File(mTreeLocation, "prebuilts/sdk/tools/dx"),
            new File(mTreeLocation, "prebuilts/sdk/tools/lib/dx.jar"),
            new File(hostTools, FN_BCC_COMPAT),
            new File(hostTools, "arm-linux-androideabi-ld"),
            new File(hostTools, "i686-linux-android-ld"),
            new File(hostTools, "mipsel-linux-android-ld"),
            new File(hostTools, FN_ZIPALIGN));

    return new TargetInfo(androidTarget, buildToolInfo);
}
 
Example #14
Source File: ProjectCreator.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Installs the project icons.
 * @param resourceFolder the resource folder
 * @param target the target of the project.
 * @return true if any icon was installed.
 */
private boolean installIcons(File resourceFolder, IAndroidTarget target)
        throws ProjectCreateException {
    // query the target for its template directory
    String templateFolder = target.getPath(IAndroidTarget.TEMPLATES);

    boolean installedIcon = false;

    installedIcon |= installIcon(templateFolder, "ic_launcher_xhdpi.png", resourceFolder,
            "drawable-xhdpi");
    installedIcon |= installIcon(templateFolder, "ic_launcher_hdpi.png", resourceFolder,
            "drawable-hdpi");
    installedIcon |= installIcon(templateFolder, "ic_launcher_mdpi.png", resourceFolder,
            "drawable-mdpi");
    installedIcon |= installIcon(templateFolder, "ic_launcher_ldpi.png", resourceFolder,
            "drawable-ldpi");

    return installedIcon;
}
 
Example #15
Source File: PlatformTarget.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean canRunOn(IAndroidTarget target) {
    // basic test
    if (target == this) {
        return true;
    }

    // if the platform has a codename (ie it's a preview of an upcoming platform), then
    // both platforms must be exactly identical.
    if (mVersion.getCodename() != null) {
        return mVersion.equals(target.getVersion());
    }

    // target is compatible wit the receiver as long as its api version number is greater or
    // equal.
    return target.getVersion().getApiLevel() >= mVersion.getApiLevel();
}
 
Example #16
Source File: AvdInfo.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new <em>invalid</em> AVD info. Values are immutable.
 * <p/>
 * Such an AVD is not complete and cannot be used.
 * The error string must be non-null.
 *
 * @param name The name of the AVD (for display or reference)
 * @param iniFile The path to the config.ini file
 * @param folderPath The path to the data directory
 * @param targetHash the target hash
 * @param target The target. Can be null, if the target was not resolved.
 * @param tag The tag id/display.
 * @param abiType Name of the abi.
 * @param properties The property map. If null, an empty map will be created.
 * @param status The {@link AvdStatus} of this AVD. Cannot be null.
 */
public AvdInfo(@NonNull  String name,
               @NonNull  File iniFile,
               @NonNull  String folderPath,
               @NonNull  String targetHash,
               @Nullable IAndroidTarget target,
               @NonNull  IdDisplay tag,
               @NonNull  String abiType,
               @Nullable Map<String, String> properties,
               @NonNull AvdStatus status) {
    mName       = name;
    mIniFile    = iniFile;
    mFolderPath = folderPath;
    mTargetHash = targetHash;
    mTarget     = target;
    mTag        = tag;
    mAbiType    = abiType;
    mProperties = properties == null ? Collections.<String, String>emptyMap()
                                     : Collections.unmodifiableMap(properties);
    mStatus     = status;
}
 
Example #17
Source File: LocalSdk.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the targets (platforms & addons) that are available in the SDK.
 * The target list is created on demand the first time then cached.
 * It will not refreshed unless {@link #clearLocalPkg} is called to clear platforms
 * and/or add-ons.
 * <p/>
 * The array can be empty but not null.
 */
@NonNull
public IAndroidTarget[] getTargets() {
    synchronized (mLocalPackages) {
        if (mReloadTargets) {
            LocalPkgInfo[] pkgsInfos = getPkgsInfos(EnumSet.of(PkgType.PKG_PLATFORM,
                                                               PkgType.PKG_ADDON));
            int n = pkgsInfos.length;
            mCachedTargets.clear();
            for (int i = 0; i < n; i++) {
                LocalPkgInfo info = pkgsInfos[i];
                assert info instanceof LocalPlatformPkgInfo;
                if (info instanceof LocalPlatformPkgInfo) {
                    IAndroidTarget target = ((LocalPlatformPkgInfo) info).getAndroidTarget();
                    if (target != null) {
                        mCachedTargets.add(target);
                    }
                }
            }
        }
        return mCachedTargets.toArray(new IAndroidTarget[mCachedTargets.size()]);
    }
}
 
Example #18
Source File: PlatformTarget.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public File getDefaultSkin() {
    // only one skin? easy.
    if (mSkins.length == 1) {
        return mSkins[0];
    }

    // look for the skin name in the platform props
    String skinName = mProperties.get(SdkConstants.PROP_SDK_DEFAULT_SKIN);
    if (skinName == null) {
        // otherwise try to find a good default.
        if (mVersion.getApiLevel() >= 4) {
            // at this time, this is the default skin for all older platforms that had 2+ skins.
            skinName = "WVGA800";                                       //$NON-NLS-1$
        } else {
            skinName = "HVGA"; // this is for 1.5 and earlier.          //$NON-NLS-1$
        }
    }

    return new File(getFile(IAndroidTarget.SKINS), skinName);
}
 
Example #19
Source File: DefaultSdkLoader.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public TargetInfo getTargetInfo(
        @NonNull String targetHash,
        @NonNull FullRevision buildToolRevision,
        @NonNull ILogger logger) {
    init(logger);

    IAndroidTarget target = mSdkManager.getTargetFromHashString(targetHash);
    if (target == null) {
        throw new IllegalStateException("failed to find target with hash string '" + targetHash + "' in: " + mSdkLocation);
    }

    BuildToolInfo buildToolInfo = mSdkManager.getBuildTool(buildToolRevision);
    if (buildToolInfo == null) {
        throw new IllegalStateException("failed to find Build Tools revision "
                + buildToolRevision.toString());
    }

    return new TargetInfo(target, buildToolInfo);
}
 
Example #20
Source File: SplashScreenActivity.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@VisibleForTesting
private void testCreateProject() {
    StdLogger log = new StdLogger(StdLogger.Level.VERBOSE);
    String sdkFolder = Environment.getSdkDir(this).getAbsolutePath();
    SdkManager sdkManager = SdkManager.createManager(sdkFolder, log);
    ProjectCreator projectCreator = new ProjectCreator(sdkManager, sdkFolder,
            ProjectCreator.OutputLevel.VERBOSE, log);

    IAndroidTarget target = null;
    IAndroidTarget[] targets = sdkManager.getTargets();
    if (DLog.DEBUG) DLog.d(TAG, "targets = " + Arrays.toString(targets));
    for (IAndroidTarget tmp : targets) {
        if (tmp.getVersion().getApiLevel() == 27) {
            target = tmp;
        }
    }

    String projectName = "DemoAndroid";
    File rootProject = new File(Environment.getSdkAppDir(), projectName);
    com.duy.android.compiler.utils.FileUtils.deleteQuietly(rootProject);
    projectCreator.createGradleProject(rootProject.getAbsolutePath(), projectName,
            "com.duy.example",
            "MainActivity", target, false, "1.0");

    File[] files = rootProject.listFiles();
    if (DLog.DEBUG) DLog.d(TAG, "files = " + Arrays.toString(files));
}
 
Example #21
Source File: LintClient.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the highest known API level.
 *
 * @return the highest known API level
 */
public int getHighestKnownApiLevel() {
    int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;

    for (IAndroidTarget target : getTargets()) {
        if (target.isPlatform()) {
            int api = target.getVersion().getApiLevel();
            if (api > max && !target.getVersion().isPreview()) {
                max = api;
            }
        }
    }

    return max;
}
 
Example #22
Source File: AddOnTarget.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(@NonNull IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = getVersion().compareTo(target.getVersion());

    // only if the version are the same do we care about platform/add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform()) {
            return +1;
        } else {
            AddOnTarget targetAddOn = (AddOnTarget)target;

            // both are add-ons of the same version. Compare per vendor then by name
            int vendorDiff = mVendor.compareTo(targetAddOn.mVendor);
            if (vendorDiff == 0) {
                return mName.compareTo(targetAddOn.mName);
            } else {
                return vendorDiff;
            }
        }

    }

    return versionDiff;
}
 
Example #23
Source File: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the path to the skin, as a relative path to the SDK.
 * @param skinName The name of the skin to find. Case-sensitive.
 * @param target The target where to find the skin.
 * @param log the log object to receive action logs. Cannot be null.
 */
@Deprecated
private String getSkinRelativePath(@NonNull String skinName,
                                   @NonNull IAndroidTarget target,
                                   @NonNull ILogger log) {
    if (log == null) {
        throw new IllegalArgumentException("log cannot be null");
    }

    // first look to see if the skin is in the target
    File skin = getSkinFolder(skinName, target);

    // skin really does not exist!
    if (skin.exists() == false) {
        log.error(null, "Skin '%1$s' does not exist.", skinName);
        return null;
    }

    // get the skin path
    String path = skin.getAbsolutePath();

    // make this path relative to the SDK location

    String sdkLocation = myLocalSdk.getPath();
    if (path.startsWith(sdkLocation) == false) {
        // this really really should not happen.
        log.error(null, "Target location is not inside the SDK.");
        assert false;
        return null;
    }

    path = path.substring(sdkLocation.length());
    if (path.charAt(0) == File.separatorChar) {
        path = path.substring(1);
    }
    return path;
}
 
Example #24
Source File: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the ini file for an AVD.
 *
 * @param name of the AVD.
 * @param avdFolder path for the data folder of the AVD.
 * @param target of the AVD.
 * @param removePrevious True if an existing ini file should be removed.
 * @throws AndroidLocationException if there's a problem getting android root directory.
 * @throws IOException if {@link File#getAbsolutePath()} fails.
 */
private File createAvdIniFile(@NonNull String name,
        @NonNull File avdFolder,
        @NonNull IAndroidTarget target,
        boolean removePrevious)
        throws AndroidLocationException, IOException {
    File iniFile = AvdInfo.getDefaultIniFile(this, name);

    if (removePrevious) {
        if (iniFile.isFile()) {
            iniFile.delete();
        } else if (iniFile.isDirectory()) {
            deleteContentOf(iniFile);
            iniFile.delete();
        }
    }

    String absPath = avdFolder.getAbsolutePath();
    String relPath = null;
    String androidPath = AndroidLocation.getFolder();
    if (absPath.startsWith(androidPath)) {
        // Compute the AVD path relative to the android path.
        assert androidPath.endsWith(File.separator);
        relPath = absPath.substring(androidPath.length());
    }

    HashMap<String, String> values = new HashMap<String, String>();
    if (relPath != null) {
        values.put(AVD_INFO_REL_PATH, relPath);
    }
    values.put(AVD_INFO_ABS_PATH, absPath);
    values.put(AVD_INFO_TARGET, target.hashString());
    writeIniFile(iniFile, values, true);

    return iniFile;
}
 
Example #25
Source File: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the paths to the system images in a properties map.
 *
 * @param target the target in which to find the system images.
 * @param abiType the abi type of the avd to find
 *        the architecture-dependent system images.
 * @param properties the properties in which to set the paths.
 * @param log the log object to receive action logs. Cannot be null.
 * @return true if success, false if some path are missing.
 */
private boolean setImagePathProperties(IAndroidTarget target,
        IdDisplay tag,
        String abiType,
        Map<String, String> properties,
        ILogger log) {
    properties.remove(AVD_INI_IMAGES_1);
    properties.remove(AVD_INI_IMAGES_2);

    try {
        String property = AVD_INI_IMAGES_1;

        // First the image folders of the target itself
        String imagePath = getImageRelativePath(target, tag, abiType);
        if (imagePath != null) {
            properties.put(property, imagePath);
            property = AVD_INI_IMAGES_2;
        }

        // If the target is an add-on we need to add the Platform image as a backup.
        IAndroidTarget parent = target.getParent();
        if (parent != null) {
            imagePath = getImageRelativePath(parent, tag, abiType);
            if (imagePath != null) {
                properties.put(property, imagePath);
            }
        }

        // we need at least one path!
        return properties.containsKey(AVD_INI_IMAGES_1);
    } catch (InvalidTargetPathException e) {
        log.error(e, e.getMessage());
    }

    return false;
}
 
Example #26
Source File: AddonPackage.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * An add-on package is typically installed in SDK/add-ons/"addon-name"-"api-level".
 * The name needs to be sanitized to be acceptable as a directory name.
 * However if we can find a different directory under SDK/add-ons that already
 * has this add-ons installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {
    File addons = new File(osSdkRoot, SdkConstants.FD_ADDONS);

    // First find if this add-on is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (!target.isPlatform() && target.getVersion().equals(mVersion)) {
            // Starting with addon-4.xsd, the addon source.properties differentiate
            // between ids and display strings. However the addon target which relies
            // on the manifest.ini does not so we need to cover both cases.
            // TODO fix when we get rid of manifest.ini for addons
            if ((target.getName().equals(getNameId()) &&
                 target.getVendor().equals(getVendorId())) ||
                (target.getName().equals(getDisplayName()) &&
                 target.getVendor().equals(getDisplayVendor()))) {
                return new File(target.getLocation());
            }
        }
    }

    // Compute a folder directory using the addon declared name and vendor strings.
    String name = encodeAddonName();

    for (int i = 0; i < 100; i++) {
        String name2 = i == 0 ? name : String.format("%s-%d", name, i); //$NON-NLS-1$
        File folder = new File(addons, name2);
        if (!folder.exists()) {
            return folder;
        }
    }

    // We shouldn't really get here. I mean, seriously, we tried hard enough.
    return null;
}
 
Example #27
Source File: TargetInfo.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
TargetInfo(
        @NonNull IAndroidTarget target,
        @NonNull BuildToolInfo buildToolInfo) {

    mTarget = target;
    mBuildToolInfo = buildToolInfo;
}
 
Example #28
Source File: Project.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the target used to build the project, or null if not known
 *
 * @return the build target, or null
 */
@Nullable
public IAndroidTarget getBuildTarget() {
    if (mTarget == null) {
        mTarget = mClient.getCompileTarget(this);
    }

    return mTarget;
}
 
Example #29
Source File: LintUtils.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert an {@link com.android.builder.model.ApiVersion} to a {@link
 * com.android.sdklib.AndroidVersion}. The chief problem here is that the {@link
 * com.android.builder.model.ApiVersion}, when using a codename, will not encode the
 * corresponding API level (it just reflects the string entered by the user in the gradle file)
 * so we perform a search here (since lint really wants to know the actual numeric API level)
 *
 * @param api     the api version to convert
 * @param targets if known, the installed targets (used to resolve platform codenames, only
 *                needed to resolve platforms newer than the tools since {@link
 *                com.android.sdklib.SdkVersionInfo} knows the rest)
 * @return the corresponding version
 */
@NonNull
public static AndroidVersion convertVersion(
        @NonNull ApiVersion api,
        @Nullable IAndroidTarget[] targets) {
    String codename = api.getCodename();
    if (codename != null) {
        AndroidVersion version = SdkVersionInfo.getVersion(codename, targets);
        if (version != null) {
            return version;
        }
        return new AndroidVersion(api.getApiLevel(), codename);
    }
    return new AndroidVersion(api.getApiLevel(), null);
}
 
Example #30
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Compiles the given aidl file.
 *
 * @param aidlFile                the AIDL file to compile
 * @param sourceOutputDir         the output dir in which to generate the source code
 * @param importFolders           all the import folders, including the source folders.
 * @param dependencyFileProcessor the dependencyFileProcessor to record the dependencies
 *                                of the compilation.
 * @throws IOException
 * @throws InterruptedException
 * @throws LoggedErrorException
 */
public void compileAidlFile(@NonNull File sourceFolder,
                            @NonNull File aidlFile,
                            @NonNull File sourceOutputDir,
                            @Nullable File parcelableOutputDir,
                            @NonNull List<File> importFolders,
                            @Nullable DependencyFileProcessor dependencyFileProcessor,
                            @NonNull ProcessOutputHandler processOutputHandler)
        throws IOException, InterruptedException, LoggedErrorException, ProcessException {
    checkNotNull(aidlFile, "aidlFile cannot be null.");
    checkNotNull(sourceOutputDir, "sourceOutputDir cannot be null.");
    checkNotNull(importFolders, "importFolders cannot be null.");
    checkState(mTargetInfo != null,
            "Cannot call compileAidlFile() before setTargetInfo() is called.");

    IAndroidTarget target = mTargetInfo.getTarget();
    BuildToolInfo buildToolInfo = mTargetInfo.getBuildTools();

    String aidl = buildToolInfo.getPath(BuildToolInfo.PathId.AIDL);
    if (aidl == null || !new File(aidl).isFile()) {
        throw new IllegalStateException("aidl is missing");
    }

    AidlProcessor processor = new AidlProcessor(
            aidl,
            target.getPath(IAndroidTarget.ANDROID_AIDL),
            importFolders,
            sourceOutputDir,
            parcelableOutputDir,
            dependencyFileProcessor != null ?
                    dependencyFileProcessor : sNoOpDependencyFileProcessor,
            mProcessExecutor,
            processOutputHandler);

    processor.processFile(sourceFolder, aidlFile);
}