private void checkTargetCompatibility(Context context, Object cookie) { if (mCompileSdkVersion > 0 && mTargetSdkVersion > 0 && mTargetSdkVersion > mCompileSdkVersion) { // NOTE: Keep this in sync with {@link #getOldValue} and {@link #getNewValue} String message = "The targetSdkVersion (" + mTargetSdkVersion + ") should not be higher than the compileSdkVersion (" + mCompileSdkVersion + ")"; report(context, cookie, DEPENDENCY, message); } }
private void checkTargetCompatibility(Context context, Object cookie) { if (mCompileSdkVersion > 0 && mTargetSdkVersion > 0 && mTargetSdkVersion > mCompileSdkVersion) { // NOTE: Keep this in sync with {@link #getOldValue} and {@link #getNewValue} String message = "The targetSdkVersion (" + mTargetSdkVersion + ") should not be higher than the compileSdkVersion (" + mCompileSdkVersion + ")"; report(context, cookie, DEPENDENCY, message); } }
private boolean checkGradlePluginDependency(Context context, GradleCoordinate dependency, Object cookie) { GradleCoordinate latestPlugin = GradleCoordinate.parseCoordinateString( SdkConstants.GRADLE_PLUGIN_NAME + GRADLE_PLUGIN_MINIMUM_VERSION); if (COMPARE_PLUS_HIGHER.compare(dependency, latestPlugin) < 0) { String message = "You must use a newer version of the Android Gradle plugin. The " + "minimum supported version is " + GRADLE_PLUGIN_MINIMUM_VERSION + " and the recommended version is " + GRADLE_PLUGIN_RECOMMENDED_VERSION; report(context, cookie, GRADLE_PLUGIN_COMPATIBILITY, message); return true; } return false; }
private boolean checkGradlePluginDependency(Context context, GradleCoordinate dependency, Object cookie) { GradleCoordinate latestPlugin = GradleCoordinate.parseCoordinateString( SdkConstants.GRADLE_PLUGIN_NAME + GRADLE_PLUGIN_MINIMUM_VERSION); if (GradleCoordinate.COMPARE_PLUS_HIGHER.compare(dependency, latestPlugin) < 0) { String message = "You must use a newer version of the Android Gradle plugin. The " + "minimum supported version is " + GRADLE_PLUGIN_MINIMUM_VERSION + " and the recommended version is " + GRADLE_PLUGIN_RECOMMENDED_VERSION; report(context, cookie, GRADLE_PLUGIN_COMPATIBILITY, message); return true; } return false; }
private void checkIntegerAsString(Context context, String value, Object valueCookie) { // When done developing with a preview platform you might be tempted to switch from // compileSdkVersion 'android-G' // to // compileSdkVersion '19' // but that won't work; it needs to be // compileSdkVersion 19 String string = getStringLiteralValue(value); if (isNumberString(string)) { String quote = Character.toString(value.charAt(0)); String message = String.format("Use an integer rather than a string here " + "(replace %1$s%2$s%1$s with just %2$s)", quote, string); report(context, valueCookie, STRING_INTEGER, message); } }
private void checkIntegerAsString(Context context, String value, Object valueCookie) { // When done developing with a preview platform you might be tempted to switch from // compileSdkVersion 'android-G' // to // compileSdkVersion '19' // but that won't work; it needs to be // compileSdkVersion 19 String string = getStringLiteralValue(value); if (isNumberString(string)) { String quote = Character.toString(value.charAt(0)); String message = String.format("Use an integer rather than a string here " + "(replace %1$s%2$s%1$s with just %2$s)", quote, string); report(context, valueCookie, STRING_INTEGER, message); } }
protected void checkOctal( @NonNull Context context, @NonNull String value, @NonNull Object cookie) { if (value.length() >= 2 && value.charAt(0) == '0' && (value.length() > 2 || value.charAt(1) >= '8' && isInteger(value)) && context.isEnabled(ACCIDENTAL_OCTAL)) { String message = "The leading 0 turns this number into octal which is probably " + "not what was intended"; try { long numericValue = Long.decode(value); message += " (interpreted as " + numericValue + ")"; } catch (NumberFormatException nufe) { message += " (and it is not a valid octal number)"; } report(context, cookie, ACCIDENTAL_OCTAL, message); } }
protected void checkOctal( @NonNull Context context, @NonNull String value, @NonNull Object cookie) { if (value.length() >= 2 && value.charAt(0) == '0' && (value.length() > 2 || value.charAt(1) >= '8' && isInteger(value)) && context.isEnabled(ACCIDENTAL_OCTAL)) { String message = "The leading 0 turns this number into octal which is probably " + "not what was intended"; try { long numericValue = Long.decode(value); message += " (interpreted as " + numericValue + ")"; } catch (NumberFormatException nufe) { message += " (and it is not a valid octal number)"; } report(context, cookie, ACCIDENTAL_OCTAL, message); } }
private void checkLocalMavenVersions(Context context, GradleCoordinate dependency, Object cookie, String groupId, String artifactId, File repository) { GradleCoordinate max = SdkMavenRepository.getHighestInstalledVersion(groupId, artifactId, repository, null, false); if (max != null) { if (COMPARE_PLUS_HIGHER.compare(dependency, max) < 0 && context.isEnabled(DEPENDENCY)) { String message = getNewerVersionAvailableMessage(dependency, max.getFullRevision()); report(context, cookie, DEPENDENCY, message); } } }
protected void checkMethodCall( @NonNull Context context, @NonNull String statement, @Nullable String parent, @NonNull Map<String, String> namedArguments, @SuppressWarnings("UnusedParameters") @NonNull List<String> unnamedArguments, @NonNull Object cookie) { String plugin = namedArguments.get("plugin"); if (statement.equals("apply") && parent == null) { boolean isOldAppPlugin = OLD_APP_PLUGIN_ID.equals(plugin); if (isOldAppPlugin || OLD_LIB_PLUGIN_ID.equals(plugin)) { String replaceWith = isOldAppPlugin ? APP_PLUGIN_ID : LIB_PLUGIN_ID; String message = String.format("'%1$s' is deprecated; use '%2$s' instead", plugin, replaceWith); report(context, cookie, DEPRECATED, message); } } }
protected void checkMethodCall( @NonNull Context context, @NonNull String statement, @Nullable String parent, @NonNull Map<String, String> namedArguments, @SuppressWarnings("UnusedParameters") @NonNull List<String> unnamedArguments, @NonNull Object cookie) { String plugin = namedArguments.get("plugin"); if (statement.equals("apply") && parent == null) { boolean isOldAppPlugin = OLD_APP_PLUGIN_ID.equals(plugin); if (isOldAppPlugin || OLD_LIB_PLUGIN_ID.equals(plugin)) { String replaceWith = isOldAppPlugin ? APP_PLUGIN_ID : LIB_PLUGIN_ID; String message = String.format("'%1$s' is deprecated; use '%2$s' instead", plugin, replaceWith); report(context, cookie, DEPRECATED, message); } } }
private void checkLocalMavenVersions(Context context, GradleCoordinate dependency, Object cookie, String groupId, String artifactId, File repository) { GradleCoordinate max = MavenRepositories.getHighestInstalledVersion( groupId, artifactId, repository, null, false, FileOpUtils.create()); if (max != null) { if (COMPARE_PLUS_HIGHER.compare(dependency, max) < 0 && context.isEnabled(DEPENDENCY)) { String message = getNewerVersionAvailableMessage(dependency, max.getRevision()); report(context, cookie, DEPENDENCY, message); } } }
+ "`provided`, not `compile`"; report(context, cookie, COMPATIBILITY, message); } else { String message = String.format("The %1$s:%2$s dependency should be " first); if (cookie != null) { report(context, cookie, COMPATIBILITY, message); } else { context.report(COMPATIBILITY, guessGradleLocation(context.getProject()), : supportedWearableVersions.toString()); if (cookie != null) { report(context, cookie, COMPATIBILITY, message); } else { context.report(COMPATIBILITY, guessGradleLocation(context.getProject()),
private void checkSupportLibraries(Context context, GradleCoordinate dependency, Object cookie) { String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); assert groupId != null && artifactId != null; // See if the support library version is lower than the targetSdkVersion if (mTargetSdkVersion > 0 && dependency.getMajorVersion() < mTargetSdkVersion && dependency.getMajorVersion() != GradleCoordinate.PLUS_REV_VALUE && // The multidex library doesn't follow normal supportlib numbering scheme !dependency.getArtifactId().startsWith("multidex") && context.isEnabled(COMPATIBILITY)) { String message = "This support library should not use a lower version (" + dependency.getMajorVersion() + ") than the `targetSdkVersion` (" + mTargetSdkVersion + ")"; report(context, cookie, COMPATIBILITY, message); } // Check to make sure you have the Android support repository installed File sdkHome = context.getClient().getSdkHome(); File repository = SdkMavenRepository.ANDROID.getRepositoryLocation(sdkHome, true); if (repository == null) { report(context, cookie, DEPENDENCY, "Dependency on a support library, but the SDK installation does not " + "have the \"Extras > Android Support Repository\" installed. " + "Open the SDK manager and install it."); } else { checkLocalMavenVersions(context, dependency, cookie, groupId, artifactId, repository); } }
report(context, cookie, COMPATIBILITY, message); } else { context.report(COMPATIBILITY, guessGradleLocation(context.getProject()), message);
private void checkPlayServices(Context context, GradleCoordinate dependency, Object cookie) { String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); assert groupId != null && artifactId != null; File sdkHome = context.getClient().getSdkHome(); File repository = SdkMavenRepository.GOOGLE.getRepositoryLocation(sdkHome, true); if (repository == null) { report(context, cookie, DEPENDENCY, "Dependency on Play Services, but the SDK installation does not " + "have the \"Extras > Google Repository\" installed. " + "Open the SDK manager and install it."); } else { checkLocalMavenVersions(context, dependency, cookie, groupId, artifactId, repository); } }
+ dependency.getMajorVersion() + ") than the `compileSdkVersion` (" + mCompileSdkVersion + ")"; report(context, cookie, COMPATIBILITY, message); } else if (mTargetSdkVersion > 0 && dependency.getMajorVersion() < mTargetSdkVersion + dependency.getMajorVersion() + ") than the `targetSdkVersion` (" + mTargetSdkVersion + ")"; report(context, cookie, COMPATIBILITY, message); FileOpUtils.create()); if (repository == null) { report(context, cookie, DEPENDENCY, "Dependency on a support library, but the SDK installation does not " + "have the \"Extras > Android Support Repository\" installed. "
FileOpUtils.create()); if (repository == null) { report(context, cookie, DEPENDENCY, "Dependency on Play Services, but the SDK installation does not " + "have the \"Extras > Google Repository\" installed. "
if (mMinSdkVersion >= 14 && "appcompat-v7".equals(dependency.getArtifactId()) && mCompileSdkVersion >= 1 && mCompileSdkVersion < 21) { report(context, cookie, DEPENDENCY, "Using the appcompat library when minSdkVersion >= 14 and " + "compileSdkVersion < 21 is not necessary"); + "can not be published with this version. Use version `%1$s` " + "instead.", version); report(context, cookie, COMPATIBILITY, message); report(context, cookie, BUNDLED_GMS, message); GradleVersion parsed = GradleVersion.tryParse(dependency.getRevision()); if (parsed != null && parsed.compareTo("1.21.6") < 0) { report(context, cookie, DEPENDENCY, "Use Fabric Gradle plugin version 1.21.6 or " + "later to improve Instant Run performance (was " + dependency.getRevision() + ")"); GradleVersion parsed = GradleVersion.tryParse(dependency.getRevision()); if (parsed != null && parsed.compareTo("2.1.2") < 0) { report(context, cookie, DEPENDENCY, "Use BugSnag Gradle plugin version 2.1.2 or " + "later to improve Instant Run performance (was " + dependency.getRevision() + ")"); report(context, cookie, issue, message);
if (mMinSdkVersion >= 14 && "appcompat-v7".equals(dependency.getArtifactId()) && mCompileSdkVersion >= 1 && mCompileSdkVersion < 21) { report(context, cookie, DEPENDENCY, "Using the appcompat library when minSdkVersion >= 14 and " + "compileSdkVersion < 21 is not necessary"); + "can not be published with this version. Use version `%1$s` " + "instead.", version); report(context, cookie, COMPATIBILITY, message); report(context, cookie, issue, message);