Yalantis/uCrop · error · IllegalArgumentException

Invalid Uri scheme%s

Error message

Invalid Uri scheme%s

What it means

BitmapLoadTask.processInputUri only supports http(s), file, and content URIs; anything else is logged and rejected with this IllegalArgumentException (note: the scheme is concatenated without a space, so the message reads e.g. 'Invalid Uri schemepackage:...'). uCrop cannot decode or copy bitmap data from an unsupported scheme.

Source

Thrown at ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java:166

        Log.d(TAG, "Uri scheme: " + mInputUri.getScheme());
        if (isDownloadUri(mInputUri)) {
            try {
                downloadFile(mInputUri, mOutputUri);
            } catch (NullPointerException | IOException e) {
                Log.e(TAG, "Downloading failed", e);
                throw e;
            }
        } else if (isContentUri(mInputUri)) {
            try {
                copyFile(mInputUri, mOutputUri);
            } catch (NullPointerException | IOException e) {
                Log.e(TAG, "Copying failed", e);
                throw e;
            }
        } else if (!isFileUri(mInputUri)) {
            String inputUriScheme = mInputUri.getScheme();
            Log.e(TAG, "Invalid Uri scheme " + inputUriScheme);
            throw new IllegalArgumentException("Invalid Uri scheme" + inputUriScheme);
        }
    }

    private void copyFile(@NonNull Uri inputUri, @Nullable Uri outputUri) throws NullPointerException, IOException {
        Log.d(TAG, "copyFile");

        if (outputUri == null) {
            throw new NullPointerException("Output Uri is null - cannot copy image");
        }

        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            inputStream = mContext.getContentResolver().openInputStream(inputUri);
            if (inputStream == null) {
                throw new NullPointerException("InputStream for given input Uri is null");
            }

View on GitHub (pinned to f788b534b4)

Solutions

  1. Convert the path to a file URI: Uri.fromFile(new File(path)).
  2. Copy assets/resources into a real file and pass Uri.fromFile of the copy.
  3. Use a FileProvider to expose the resource as a content:// URI and pass that.
  4. Log the actual inputUri.getScheme() and make sure it is http, https, file, or content before launching uCrop.

Example fix

// before
UCrop.of(Uri.parse("/storage/emulated/0/DCIM/photo.jpg"), destUri);
// after
UCrop.of(Uri.fromFile(new File("/storage/emulated/0/DCIM/photo.jpg")), destUri);
Defensive patterns

Strategy: validation

Validate before calling

String scheme = inputUri != null ? inputUri.getScheme() : null;
if (!"http".equals(scheme) && !"https".equals(scheme) && !"file".equals(scheme) && !"content".equals(scheme)) {
    throw new IllegalArgumentException("Unsupported uCrop input scheme: " + scheme);
}

Type guard

boolean isSupportedForUCrop(android.net.Uri uri) {
    if (uri == null || uri.getScheme() == null) return false;
    String s = uri.getScheme().toLowerCase();
    return s.equals("http") || s.equals("https") || s.equals("file") || s.equals("content");
}

Try / catch

try {
    UCrop.of(inputUri, outputUri).start(activity);
} catch (IllegalArgumentException e) {
    Toast.makeText(activity, "Unsupported image source", Toast.LENGTH_SHORT).show();
}

Prevention

When it happens

Trigger: Passing a source Uri whose scheme is not http, https, file, or content to UCrop.of()/BitmapLoadTask — e.g. asset://, res://, data:, android.resource://, or a bare path string wrapped in Uri.parse().

Common situations: Wrapping a relative or absolute filesystem path with Uri.parse instead of Uri.fromFile; using bundled asset or drawable resource URIs; receiving a URI from a third-party SDK with an exotic scheme.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/ce488f3fcf21d6e5. Report an issue: GitHub.