我想在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