JGit failure in Cloning repository

96 Views Asked by At

I am currently facing an issue in JGit with Cloning repository. I used CloneCommand object to clone a my own public repository but it failed. I got these messages from a ProgressMonitor

-remote: Compressing objects
-receiving objects
-resolving deltas
-Checking out files [And here app crashed]

I used the following code to clone repository



ExecutorService executor = Executors.newSingleThreadExecutor();

        final Handler handler = new Handler(Looper.getMainLooper());

        executor.execute(

                new Runnable() {

                    @Override

                    public void run() {

                        try {

                            Log.e("GitDebug",file.getAbsolutePath());

                            Log.e("GitDebug",username);

                            // Log.e("GitDebug",password);

                            Log.e("GitDebug",url);

                            CloneCommand clone = Git.cloneRepository();

                            clone.setURI(url);

                            clone.setDirectory(file);

                            clone.setBare(false);

                            clone.setCloneAllBranches(true);

                            if (setUseCredentialsProvider) {

                                // clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));

                            }

                            clone.setProgressMonitor(

                                new ProgressMonitor() {

                                    @Override

                                     public void start(int arg0) {}

                                     @Override

                                     public void beginTask(String arg0, int arg1) {

                                         gitCallback.onProgress(arg0,arg1);

                                     }

                                     @Override

                                     public void update(int arg0) {}

                                     @Override

                                     public void endTask() {}

                                     @Override

                                     public boolean isCancelled() {

                                         return false;

                                     }

                                     @Override

                                     public void showDuration(boolean arg0) {}

                            });

                            clone.call();

                            gitCallback.onProgressComplete(true, "Download complete");

                        } catch (GitAPIException | JGitInternalException e) {

                            gitCallback.onProgressComplete(false, e.getMessage());

                        }

                    }

                });

Here is the crash message:



java.lang.NoSuchMethodError: No virtual method transferTo(Ljava/io/OutputStream;)J in class Ljava/io/InputStream; or its super classes (declaration of 'java.io.InputStream' appears in /apex/com.android.runtime/javalib/core-oj.jar)

    at org.eclipse.jgit.dircache.DirCacheCheckout.getContent(DirCacheCheckout.java:1684)

    at org.eclipse.jgit.dircache.DirCacheCheckout.getContent(DirCacheCheckout.java:1609)

    at org.eclipse.jgit.dircache.DirCacheCheckout.checkoutEntry(DirCacheCheckout.java:1535)

    at org.eclipse.jgit.dircache.DirCacheCheckout.doCheckout(DirCacheCheckout.java:569)

    at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:471)

    at org.eclipse.jgit.api.CloneCommand.checkout(CloneCommand.java:399)

    at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:220)

    at android.code.editor.utils.GitCloneHandler$1.run(GitCloneHandler.java:138)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)

    at java.lang.Thread.run(Thread.java:919)


InGradle

compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
....
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-r'

I there any way to fix this error?

1

There are 1 best solutions below

5
Sören On

InputStream.transferTo was added in API level 33. You need to use at least API level 33.