我正在尝试在Android Java上克隆存储库,但在调用方法toPath()
时出现错误。显然,File对象没有toPath()
方法。
public void gitClone() throws GitAPIException {
// File dir = new File(_ctx.getExternalFilesDir(null) + File.separator + "openshift_files");
Bundle b2 = getIntent().getExtras();
//File localPath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
final File localPath = new File(getExternalFilesDir(null) + File.separator + getCurrentApp().getName());
Git.cloneRepository()
.setURI(getUrlGit())
.setDirectory(localPath)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(b2.getString("OPEN_SHIFT_USER"), b2.getString("OPEN_SHIFT_PASSWORD")))
.call();
System.out.println("Success!");
}
这是堆栈跟踪
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
E/AndroidRuntime: Process: com.javier.openshift, PID: 22919
E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime: at android.os.AsyncTask$3.done(AsyncTask.java:304)
E/AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
E/AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E/AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime: Caused by: java.lang.NoSuchMethodError: No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File; or its super classes (declaration of 'java.io.File' appears in /system/framework/core-libart.jar)
E/AndroidRuntime: at org.eclipse.jgit.util.FileUtil.exists(FileUtil.java:149)
E/AndroidRuntime: at org.eclipse.jgit.util.FS_POSIX.exists(FS_POSIX.java:275)
E/AndroidRuntime: at org.eclipse.jgit.internal.storage.file.ObjectDirectory.exists(ObjectDirectory.java:193)
E/AndroidRuntime: at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:207)
E/AndroidRuntime: at org.eclipse.jgit.lib.BaseRepositoryBuilder.build(BaseRepositoryBuilder.java:579)
E/AndroidRuntime: at org.eclipse.jgit.api.InitCommand.call(InitCommand.java:113)
E/AndroidRuntime: at org.eclipse.jgit.api.CloneCommand.init(CloneCommand.java:161)
E/AndroidRuntime: at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:132)
E/AndroidRuntime: at com.javier.apps.AppsActivity.gitClone(AppsActivity.java:981)
E/AndroidRuntime: at com.javier.apps.AppsActivity$AsyncTaskCloneRepository.doInBackground(AppsActivity.java:1002)
E/AndroidRuntime: at com.javier.apps.AppsActivity$AsyncTaskCloneRepository.doInBackground(AppsActivity.java:985)
E/AndroidRuntime: at android.os.AsyncTask$2.call(AsyncTask.java:292)
E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
答案 0 :(得分:4)
您使用的是最新版本的JGit。从JGit 4.0.0开始,最小的Java版本从Java 5升级到Java 7(see Eclipse documentation here)。 JGit正在使用Java 7 Path
API,它不适用于您正在使用的JDK。
你应该降级到JGit 3.7.1(这是3.x行中最新的)。
答案 1 :(得分:0)
即使使用Java 7,Android中也不能使用java.nio.file.Path
以及JGit所依赖的其他nio
类。更多细节在这里:
Android import java.nio.file.Files; cannot be resolved
所以@Tinaki的答案仍然是正确的,但原因不同。不幸的是,在Android上,我们被锁定到JGit 3.7.1,直到那些nio
类可用,即使使用Java 7也是如此。