diff options
6 files changed, 29 insertions, 13 deletions
diff --git a/android/cpp/JNI.cpp b/android/cpp/JNI.cpp index 3b1801c4c6..708063f240 100644 --- a/android/cpp/JNI.cpp +++ b/android/cpp/JNI.cpp @@ -21,6 +21,7 @@ namespace mbgl { namespace android { std::string cache_path; +std::string data_path; jmethodID on_map_changed_id = nullptr; @@ -139,9 +140,10 @@ using namespace mbgl::android; // TODO: wrap C++ exceptions? // TODO: wrap other sorts of exceptions? eg coffee catch -jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_) { +jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring cache_path_, jstring data_path_) { LOG_VERBOSE("nativeCreate"); cache_path = std_string_from_jstring(env, cache_path_); + data_path = std_string_from_jstring(env, data_path_); NativeMapView* native_map_view = new NativeMapView(env, obj); if (native_map_view == nullptr) { throw_error(env, "Unable to create NativeMapView."); @@ -754,7 +756,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { // NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the array correctly (too large) std::array<JNINativeMethod, 60> methods = {{ // Can remove the extra brace in C++14 - { "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) }, + { "nativeCreate", "(Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) }, { "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) }, { "nativeInitializeDisplay", "(J)V", reinterpret_cast<void*>(&nativeInitializeDisplay) }, { "nativeTerminateDisplay", "(J)V", reinterpret_cast<void*>(&nativeTerminateDisplay) }, diff --git a/android/cpp/NativeMapView.hpp b/android/cpp/NativeMapView.hpp index 5e12084b38..75aba6985b 100644 --- a/android/cpp/NativeMapView.hpp +++ b/android/cpp/NativeMapView.hpp @@ -15,6 +15,7 @@ namespace mbgl { namespace android { extern std::string cache_path; +extern std::string data_path; extern jmethodID on_map_changed_id; diff --git a/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java index 8730cf4cad..f12468dcec 100644 --- a/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java +++ b/android/java/lib/src/main/java/com/arieslabs/assetbridge/Assetbridge.java @@ -9,8 +9,12 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; public class Assetbridge { + + private static final String TAG = "Assetbridge"; + /*static { System.loadLibrary("assetbridge"); }*/ @@ -19,16 +23,21 @@ public class Assetbridge { public static void unpack(Context c) { try { - // first let's get the temp directory - String tmpdir = c.getCacheDir().getPath(); + // first let's get the data directory + String datadir = c.getFilesDir().getAbsolutePath(); + Log.v(TAG, "Extracting assets to " + datadir); // now we need the assetmanager AssetManager am = c.getAssets(); - String[] assets = am.list(""); + + // only extract what we need + ArrayList<String> assets = new ArrayList<String>(); + assets.add("ca-bundle.crt"); + assets.add("styles"); // iterate on the files... for(String asset : assets) { - copyAssetFolder(am, asset, tmpdir + "/" + asset); + copyAssetFolder(am, asset, datadir + "/" + asset); } // last, set the ASSETDIR environment variable for the C @@ -44,6 +53,7 @@ public class Assetbridge { public static void copyAssetFolder(AssetManager am, String src, String dest) throws IOException { + Log.v(TAG, "Copying " + src); InputStream srcIS = null; File destfh; @@ -58,6 +68,8 @@ public class Assetbridge { isDir = true; } + Log.v(TAG, src + " was " + (isDir ? "a dir" : "a file")); + // either way, we'll use the dest as a File destfh = new File(dest); diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java index ebec3db83f..37db7d55f4 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java @@ -116,18 +116,19 @@ public class MapView extends SurfaceView { } // Get the cache path - String cachePath = context.getCacheDir().getPath(); + String cachePath = context.getCacheDir().getAbsolutePath(); + String dataPath = context.getFilesDir().getAbsolutePath(); // Extract the asset files Assetbridge.unpack(context); // Load the map style and API key //mStyleUrl = "https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json"; - mStyleUrl = "file://" + cachePath + "/styles/styles/bright-v6.json"; + mStyleUrl = "file://" + dataPath + "/styles/styles/bright-v6.json"; mAccessToken = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ"; // Create the NativeMapView - mNativeMapView = new NativeMapView(this, cachePath); + mNativeMapView = new NativeMapView(this, cachePath, dataPath); mNativeMapView.setStyleURL(mStyleUrl); mNativeMapView.setAccessToken(mAccessToken); mNativeMapView.setDebug(true); diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java index 974c408b6c..e0e005f66a 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java @@ -37,11 +37,11 @@ class NativeMapView { // Constructors // - public NativeMapView(MapView mapView, String cachePath) { + public NativeMapView(MapView mapView, String cachePath, String dataPath) { mMapView = mapView; // Create the NativeMapView - mNativeMapViewPtr = nativeCreate(cachePath); + mNativeMapViewPtr = nativeCreate(cachePath, dataPath); } // @@ -407,7 +407,7 @@ class NativeMapView { super.finalize(); } - private native long nativeCreate(String cachePath); + private native long nativeCreate(String cachePath, String dataPath); private native void nativeDestroy(long nativeMapViewPtr); diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index db057bc1b7..5238283fdb 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -423,7 +423,7 @@ void start_request(void *const ptr) { #ifndef __ANDROID__ std::string ca_path = "ca-bundle.crt"; #else - std::string ca_path = mbgl::android::cache_path + "/ca-bundle.crt"; + std::string ca_path = mbgl::android::data_path + "/ca-bundle.crt"; #endif // Carry on the shared pointer in the private information of the CURL handle. |