Android设备上的jGit使用情况
我想在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
在哪里的问题?可能是我使用不正确的库?
Git有一些Android客户端。
下面是对这些工具的部分列表:
从市场上的另一种应用:
这是悲伤的... – Orgatres
很抱歉,但没有什么可以做的。 Git只在win/unix/mac等版本上发布,不适用于移动平台。 – CodeWizard
感谢您的解释) – Orgatres
它可以做到!查看为Android提供git-client的agit application的源代码。
我没有仔细检查它,但似乎使用补丁版本的JGit和Repository类的不同实现来避免Android上不可能实现的直接文件访问。
它可能有一些限制,即现在没有提交/写入支持,但至少它可以显示基本访问是如何可能的,并且如果您需要更多功能,您可以从那里构建它。
你在我们的android设备上安装了git吗?我不这样做。 – CodeWizard
不,我没有在Android设备上安装git ...必须采取什么措施在Android设备上创建本地存储库? – Orgatres