use of com.android.sdklib.repositoryv2.AndroidSdkHandler in project kotlin by JetBrains.
the class LintClient method getTargets.
/**
* Returns all the {@link IAndroidTarget} versions installed in the user's SDK install
* area.
*
* @return all the installed targets
*/
@NonNull
public IAndroidTarget[] getTargets() {
if (mTargets == null) {
AndroidSdkHandler sdkHandler = getSdk();
if (sdkHandler != null) {
ProgressIndicator logger = getRepositoryLogger();
Collection<IAndroidTarget> targets = sdkHandler.getAndroidTargetManager(logger).getTargets(logger);
mTargets = targets.toArray(new IAndroidTarget[targets.size()]);
} else {
mTargets = new IAndroidTarget[0];
}
}
return mTargets;
}
use of com.android.sdklib.repositoryv2.AndroidSdkHandler in project kotlin by JetBrains.
the class ApiDetector method beforeCheckProject.
@Override
public void beforeCheckProject(@NonNull Context context) {
if (mApiDatabase == null) {
mApiDatabase = ApiLookup.get(context.getClient());
if (mApiDatabase == null && !mWarnedMissingDb) {
mWarnedMissingDb = true;
context.report(IssueRegistry.LINT_ERROR, Location.create(context.file), "Can't find API database; API check not performed");
} else {
// See if you don't have at least version 23.0.1 of platform tools installed
AndroidSdkHandler sdk = context.getClient().getSdk();
if (sdk == null) {
return;
}
LocalPackage pkgInfo = sdk.getLocalPackage(SdkConstants.FD_PLATFORM_TOOLS, context.getClient().getRepositoryLogger());
if (pkgInfo == null) {
return;
}
Revision revision = pkgInfo.getVersion();
// The platform tools must be at at least the same revision
// as the compileSdkVersion!
// And as a special case, for 23, they must be at 23.0.1
// because 23.0.0 accidentally shipped without Android M APIs.
int compileSdkVersion = context.getProject().getBuildSdk();
if (compileSdkVersion == 23) {
if (revision.getMajor() > 23 || revision.getMajor() == 23 && (revision.getMinor() > 0 || revision.getMicro() > 0)) {
return;
}
} else if (compileSdkVersion <= revision.getMajor()) {
return;
}
// Pick a location: when incrementally linting in the IDE, tie
// it to the current file
List<File> currentFiles = context.getProject().getSubset();
Location location;
if (currentFiles != null && currentFiles.size() == 1) {
File file = currentFiles.get(0);
String contents = context.getClient().readFile(file);
int firstLineEnd = contents.indexOf('\n');
if (firstLineEnd == -1) {
firstLineEnd = contents.length();
}
location = Location.create(file, new DefaultPosition(0, 0, 0), new DefaultPosition(0, firstLineEnd, firstLineEnd));
} else {
location = Location.create(context.file);
}
context.report(UNSUPPORTED, location, String.format("The SDK platform-tools version (%1$s) is too old " + " to check APIs compiled with API %2$d; please update", revision.toShortString(), compileSdkVersion));
}
}
}
use of com.android.sdklib.repositoryv2.AndroidSdkHandler in project kotlin by JetBrains.
the class IntellijLintClient method getSdk.
@Nullable
@Override
public AndroidSdkHandler getSdk() {
if (mSdk == null) {
Module module = getModule();
AndroidSdkHandler sdk = getLocalSdk(module);
if (sdk != null) {
mSdk = sdk;
} else {
for (Module m : ModuleManager.getInstance(myProject).getModules()) {
sdk = getLocalSdk(m);
if (sdk != null) {
mSdk = sdk;
break;
}
}
if (mSdk == null) {
mSdk = super.getSdk();
}
}
}
return mSdk;
}
Aggregations