我想在Android设备上执行jGit库。我想创建本地存储库。Android设备上的jGit使用情况
该代码正在PC:
File fRepositoryDir = new File("D:/My/jgittestrpo");
if (!fRepositoryDir.exists()) {
fRepositoryDir.mkdirs();
}
Repository localRepo;
Git git;
try {
localRepo = new FileRepository(fRepositoryDir.getAbsolutePath() + "/.git");
localRepo.create();
} catch (Exception e) {
e.printStackTrace();
}
这在Android设备上相同的代码不工作:
File fRepositoryDir = new File(getFilesDir().getAbsolutePath() + File.separator + "repository");
//File fRepositoryDir = new File(Environment.getExternalStorageDirectory() + File.separator + "repository"); // Trying on sd card, not working too
if (!fRepositoryDir.exists()) {
fRepositoryDir.mkdirs();
}
Repository localRepository;
try {
localRepository = new FileRepository(fRepositoryDir.getAbsolutePath() + File.separator + ".git");
//localRepository = new FileRepository("/data/data/com.examplecompany.gitexample/files/repository/.git"); // Trying to set repo folder directly
localRepository.create();
} catch (Exception e) {
e.printStackTrace();
}
异常Android设备上:
FATAL EXCEPTION: main
Process: com.examplecompany.gitexample, PID: 2036
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
... 11 more
Caused by: java.lang.VerifyError: org/eclipse/jgit/internal/storage/file/ObjectDirectory
at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:221)
at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:145)
at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:159)
at com.examplecompany.gitexample.MainActivity.onLoginClick(MainActivity.java:173)
... 14 more
在哪里的问题?可能是我使用不正确的库?
你在我们的android设备上安装了git吗?我不这样做。 – CodeWizard
不,我没有在Android设备上安装git ...必须采取什么措施在Android设备上创建本地存储库? – Orgatres