Graphhopper on Android offline routing pbf file error - android

I'm trying to create an application that combines Osmdroid with Graphhoper to achieve offline routing on a city area. I exported osm file from Open Street Maps and converted that file to pbf. The problem is that an application fails to load the pbf file because Graphhoper trying to parse the pbf file using java.xml.stream which is not available on Android devices. Here is the function that I'm using to load the pbf file.
public void setRouting(){
File dir = new File(Environment.getExternalStorageDirectory(),"osmdroid");
File osmFile=new File(dir,"offline-map.osm.pbf");
if(!osmFile.exists()){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("File doesn't exist").setTitle("Error");
AlertDialog dialog = builder.create();
dialog.show();
return;
}
GraphHopper hopper = new GraphHopper().forMobile();
hopper.setEncodingManager(encodingManager);
hopper.setGraphHopperLocation(getApplicationContext().getFilesDir().getPath());
hopper.setOSMFile(osmFile.getAbsolutePath());
hopper.setCHShortcuts("fastest");
hopper.importOrLoad();
}
I know that it is possible to convert osm to ghz (which works in my case):
https://github.com/graphhopper/graphhopper/blob/0.3/docs/android/index.md
but I can't execute this:
./graphhopper.sh import <your-osm-file>
on windows OS.
I'm not using Maven to include Graphhopper. I inserted jar into libs folder.
How can I import a osm file into my project to achieve offline routing?
I finally managed to resolve this.
This is how I did it:
Download Apache maven
Scroll down to Install instruction - Windows section and follow maven installation steps
Set Enviroment User Variable MAVEN_HOME ie: C:\Program Files\Apache Software Foundation\apache-maven-3.2.1. (important use same value as for M2_HOME)
Clone Graphopper git to your local machine git or download repository as zip and extract it somewhere on your local disk
Download and install Cygwin
Run Cygwin
$ cd /cygdrive/
You are now positioned on root type "ls" to see all drives on computer
Position your self into Graphhopper git root.
ie for c:\git\graphopper:
$ cd c
$ cd git
$ cd graphhoper
see linux navigation tips for how to navigate
10. Copy your filename.osm file to Graphhoper git root
11. $ ./graphhopper.sh import filename.osm
12. You shud have folder filename-gh in your Graphopper git root folder which have all you need.
13. Copy that folder to your mobile device
14. You can now use something like this:
`
File dir = new File(Environment.getExternalStorageDirectory(),"map-parent-folder-name");
File ghDir=new File(dir.getAbsolutePath(),"filename-gh");
hopper = new GraphHopper().forMobile();
hopper.setCHShortcuts("fastest");
hopper.load(ghDir.getAbsolutePath());
to init graphopper
Two more tips. If you don't have Graphopper jar (graphhopper-0.3-SNAPSHOT.jar) you can create one with:
$ ./graphhopper.sh build filename.osm
new jar is located in core/target/ folder
You will need trove-3.0.3.jar which you may download here. Just add trove-3.0.3.jar from the zip into the libs folder of your project
I hope that I didn't forget anything :)

You cannot import the xml/pbf on Android (yet). As you are on windows have a look at the docs how to execute the import via cygwin.

Related

How to add android "SDK Update Site" via command line

I am using the android's sdkmanager commandline tool to update the SDK and I want to add an update site for addons. How can I do that only from commandline. I cannot use UX tool as I am accessing the host via ssh.
You will need to create this a file named repositories.cfg under your ~/.android/ folder.
Paste the following content into the file and modify it as needed.
### User Sources for Android Repository
#Tue Dec 12 15:45:09 PST 2017
disp02=Url1
disp01=Url2
disp00=Url3
count=3
enabled02=true
enabled01=true
enabled00=true
src02=http\://somewhere.com/some-extras-2/SomeArtifact2/some-extra-artifact.xml
src01=http\://somewhere.com/some-extras-1/SomeArtifact1/some-extra-artifact.xml
src00=http\://somewhere.com/some-extras-0/SomeArtifact0/some-extra-artifact.xml
Looks like still nothing better than writing a custom script to achieve these steps:
Download addon.xml
Parse it to get the location of a package archive[1]
Download package and extract to $ANDROID_SDK_HOME/add-ons
Convert addon.xml to package.xml and place it in addon directory in Android SDK
Here is my script to do this https://gist.github.com/CAMOBAP795/b5664b05ce2130de8192516fd4c4b9b0
Prerequisites:
- wget
- libxml2-utils
- xsltproc
[1] During development I observed that there are several XSD schemes, so my script doesn' cover all cases

Interface files missing from downloaded SDK source code

I try to step in the sdk source as depth as possible.
Let's say I step into my sdk source, ~/Android/Sdk/sources/android-24/android/app/ApplicationPackageManager.java:
import android.content.pm.IPackageManager;
But no such file IPackageManager.java inside pm directory:
[xiaobai#localhost pm]$ pwd
/home/xiaobai/Android/Sdk/sources/android-24/android/content/pm
[xiaobai#localhost pm]$ ls I*
InstrumentationInfo.java IntentFilterVerificationInfo.java
[xiaobai#localhost pm]$
Why is it not there? Am I misunderstanding something?
IPackageManager is an aidl file. It appears aidl files are not included when you download the source code package via the SDK tools.
You can browse the online repository to find it though: IPackageManager.aidl.
You can view the file content in a browser.

Android-Studio git over ssh

I got a git-server on my Raspberry Pi with gitweb as webinterface.
Its working so far.
Now I want to connect via Android Studio with the built-in ssh to it.
My project dir is :
/home/git/straff.git
I'll connect with this command from Android Studio:
:ssh:git#192.168.178.21:/straff
Android Studio is giving me this when I test the connection:
Cannot access /straff/CVSROOT
I am using password auth for it. I can access from command line tools to my repo...
Why Android Studio cant?
I can access from command line tools to my repo...
Why Android Studio cant?
Your error is you are trying to access 192.168.178.21:/straff which is /straff on that machine. Either provide the full path like below or use this one
:ssh:git#192.168.178.21:straff
Old post:
You can try to specify the full path to Android Studio:
:ssh:git#192.168.178.21:/home/git/straff
I am using password auth for it.
That means the ssh connection doesn't use a private/public (~/.ssh/id_rsa(.pub)) key.
A good tutorial to follow with Android Studio is the one titled "How to push to a remote Git repository over SSH with private/public key authentication using Android Studio".
Hmm, should the URL be like:
ssh://git#192.168.178.21/straff
I had problems with setting ssh key. I solved it by creating id_rsa -titled file under .ssh-directory (under user home-dir) and putting my RSA-stuff into it.
If you already have the remote git repository, which you want to check out, and you have a private key, then the instructions on https://www.londonappdeveloper.com/how-to-push-to-a-remote-git-repository-over-ssh-with-privatepublic-key-authentication-using-android-studio/ might help to some extent, but they are for older version of Android Studio and they are too complicated.
What you need to do (especially when you start from scratch) is:
Ensure that your key is an OpenSSH key, and that it's a private key (not a public key). This is where the above mentioned instructions are misleading - they point to the key in supposedly Putty format (the .ppk file), and this doesn't work. If you have a Putty key, use Putty's puttygen.exe tool to export the private key in OpenSSH format.
Create the config file as described in those instructions. I.e.
create the text file named config in .ssh subdirectory of your user directory. In my case the path would be C:\Users\Eugene.ssh\config.
Put the following to this file:
Host my-host.com
HostName my-host.com
Port 22
IdentityFile C:\Users\Eugene.ssh\my-private-key-for-my-host.openssh
(the original instructions include indentation of lines 2-4, but I couldn't add any indentation here).
Use Checkout Project From Version Control menu item in Android Studio's welcome screen to initiate GIT checkout.
Use the following settings during checkout (curly brackets contain the values which you replace with yours):
Git Repository URL: {projectalias}#{my-host.com}:base/{projectname}
Parent directory: eg. "z:\Projects" The path which must exist, and in which the new project is created
Project directory: eg. "myproject". The directory with this name will be created in Parent directory, so the files will be checked out to Parent_directory\Project_directory, eg. "z:\Projects\myproject".

How to extract tar (ed) Android repo?

I'm restoring my Linux partition from backups (mostly non compressed tarballs). I'm facing a problem while extracting a tarball which is backup of synced android repo. I tared my existing repo by simple tar -cf command and i'm extracting it using tar -xf blah.tar. I'm getting the following error.
http://pastebin.com/rkyu9qvD
Dump of tar -tvf blah.tar
http://pastebin.com/WyrwU3v2 (truncated)
I think the problem is symlinks. For example consider failed extraction of
.repo/projects/packages/providers/DownloadProvider.git/info/exclude
If the files are extracted serially as show by -t (correct me if i'm wrong) then first it should extract .repo/projects/packages/providers/DownloadProvider.git/info because it is symlink (Look at dump
lrwxrwxrwx bootmgr/bootmgr 0 2014-03-23 11:02 .repo/projects/packages/providers/DownloadProvider.git/info -> ../../../../project-objects/platform/packages/providers/DownloadProvider.git/info
) I thinks that is why it is getting error while extracting it.
Many other files are extracted wrongly in this way for ex, first it'll create a/b/c.x path to extract c.x but later founds that b is symlink to another directory and then throws error like file already exist
So any ideas how i should extract it or it is impossible.
If it is impossible then any other better way to backup existing Android repo so that i can move it to other HDD.
From the tar documentation:
Normally, when tar archives a symbolic link, it writes a block to the archive naming the target of the link. In that way, the tar archive is a faithful record of the file system contents. When--dereference' (-h') is used with--create' (-c'), tar archives the files symbolic links point to, instead of the links themselves.
So try to archive with tar -chf ... and I guess your issues will be solved.

Vagrant (ionic-box) not syncing on host folder

Why is it when I install ionic-box (for Ionicframework) it's not syncing in my folder?
I added this line
config.vm.synced_folder "projects", "/vagrant_projects"
to Vagrantfile but it's not working. i still need to create manually the folder vagrant_projects in home/vagrant directory which I thought will be create automatically when creating/installing ionic-box.
I already added a new project inside vagrant_projects but i noticed it is not reflecting in the host folder projects.
BtW, I created the folder projects inside the directory where i extract the Vagrantfile.
Here's my reference: http://www.sitepoint.com/ionic-box-vagrant-configuration-hybrid-mobile-apps/ and http://java.dzone.com/articles/getting-started-building-0
config.vm.synced_folder "projects", "/vagrant_projects" will create vagrant_projects folder at / not home/vagrant. So the path of your folder vagrant_projects will be /vagrant_projects not home/vagrant/vagrant_projects.
Your configuration is correct just login to your vm via vagrant ssh and execute following command
ls /vagrant_projects
you should be able to see your synced data now.
vagrant tutorial

Categories

Resources