Skip to content

Commit 1ff2282

Browse files
Remove old android project. Add android-libpdf2htmlex (android-3rdparty will be generated on -libpdf2htmlex) and android-sample-app
1 parent 7ed5bf9 commit 1ff2282

File tree

65 files changed

+1119
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1119
-67
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 29
5+
defaultConfig {
6+
minSdkVersion 16
7+
targetSdkVersion 29
8+
}
9+
buildTypes {
10+
release {
11+
externalNativeBuild {
12+
cmake {
13+
arguments '-DCMAKE_BUILD_TYPE=MinSizeRel', '-DBUILD_3RDPARTY_BINARIES=OFF'
14+
}
15+
}
16+
}
17+
debug {
18+
externalNativeBuild {
19+
cmake {
20+
arguments '-DBUILD_3RDPARTY_BINARIES=OFF'
21+
}
22+
}
23+
}
24+
}
25+
externalNativeBuild {
26+
cmake {
27+
path "../../CMakeLists.txt"
28+
buildStagingDirectory "../../build/libpdf2htmlex/"
29+
version "3.10.2"
30+
}
31+
}
32+
}
33+

android/app/src/main/AndroidManifest.xml renamed to android-libpdf2htmlex/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
android:supportsRtl="true">
1111
</application>
1212

13-
</manifest>
13+
</manifest>
File renamed without changes.

android/gradle.properties renamed to android-libpdf2htmlex/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ org.gradle.jvmargs=-Xmx1536m
1212
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1313
# org.gradle.parallel=true
1414

15+
buildDir=../../build/gradle_libpdf2htmlex
1516

android/gradle/wrapper/gradle-wrapper.properties renamed to android-libpdf2htmlex/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
File renamed without changes.
File renamed without changes.
File renamed without changes.

android-sample-app/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild

android-sample-app/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android-sample-app/app/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "29.0.2"
6+
defaultConfig {
7+
applicationId "com.viliussutkus89.pdf2htmlex.android_sample_app"
8+
minSdkVersion 16
9+
targetSdkVersion 29
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
externalNativeBuild {
21+
cmake {
22+
path "src/main/cpp/CMakeLists.txt"
23+
version "3.10.2"
24+
}
25+
}
26+
}
27+
28+
dependencies {
29+
implementation fileTree(dir: 'libs', include: ['*.jar'])
30+
implementation 'androidx.appcompat:appcompat:1.0.2'
31+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
32+
testImplementation 'junit:junit:4.12'
33+
androidTestImplementation 'androidx.test:runner:1.2.0'
34+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
35+
36+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
37+
}
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.viliussutkus89.pdf2htmlex.android_sample_app;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.InstrumentationRegistry;
6+
import androidx.test.runner.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getTargetContext();
24+
25+
assertEquals("com.viliussutkus89.pdf2htmlex.android_sample_app", appContext.getPackageName());
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.viliussutkus89.pdf2htmlex.android_sample_app">
4+
<application
5+
android:allowBackup="true"
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:roundIcon="@mipmap/ic_launcher_round"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
14+
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
<provider
19+
android:name="androidx.core.content.FileProvider"
20+
android:authorities="${applicationId}.provider"
21+
android:exported="false"
22+
android:grantUriPermissions="true">
23+
<meta-data
24+
android:name="android.support.FILE_PROVIDER_PATHS"
25+
android:resource="@xml/provider_paths"/>
26+
</provider>
27+
</application>
28+
</manifest>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# For more information about using CMake with Android Studio, read the
2+
# documentation: https://d.android.com/studio/projects/add-native-code.html
3+
4+
# Sets the minimum version of CMake required to build the native library.
5+
6+
cmake_minimum_required(VERSION 3.4.1)
7+
8+
# Creates and names a library, sets it as either STATIC
9+
# or SHARED, and provides the relative paths to its source code.
10+
# You can define multiple libraries, and CMake builds them for you.
11+
# Gradle automatically packages shared libraries with your APK.
12+
13+
add_library( # Sets the name of the library.
14+
native-lib
15+
16+
# Sets the library as a shared library.
17+
SHARED
18+
19+
# Provides a relative path to your source file(s).
20+
native-lib.cpp)
21+
22+
# Searches for a specified prebuilt library and stores the path as a
23+
# variable. Because CMake includes system libraries in the search path by
24+
# default, you only need to specify the name of the public NDK library
25+
# you want to add. CMake verifies that the library exists before
26+
# completing its build.
27+
28+
find_library( # Sets the name of the path variable.
29+
log-lib
30+
31+
# Specifies the name of the NDK library that
32+
# you want CMake to locate.
33+
log)
34+
35+
# Specifies libraries CMake should link to your target library. You
36+
# can link multiple libraries, such as libraries you define in this
37+
# build script, prebuilt third-party libraries, or system libraries.
38+
39+
target_link_libraries( # Specifies the target library.
40+
native-lib
41+
42+
# Links the target library to the log library
43+
# included in the NDK.
44+
${log-lib}
45+
)
46+
47+
48+
##### HOWTO INCLUDE libpdf2htmlEX.so ########
49+
include(${CMAKE_SOURCE_DIR}/../jniLibs/pdf2htmlEX.cmake)
50+
target_link_libraries(native-lib pdf2htmlEX)
51+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <jni.h>
2+
#include <string>
3+
#include <vector>
4+
#include "pdf2htmlEX.h"
5+
6+
// Creating char ** by hand is rather annoying.
7+
// I'll rather take vector<string> and convert it before calling.
8+
void vector_to_char_pp(const std::vector<const std::string> & input, int * argc, char *** argv) {
9+
*argv = nullptr;
10+
*argc = 0;
11+
12+
size_t sz = input.size();
13+
if (sz == 0) {
14+
return;
15+
}
16+
char ** output = new char *[sz];
17+
int i = 0;
18+
for (const std::string & s: input) {
19+
size_t len = s.length();
20+
output[i] = new char[len+1];
21+
output[i][len] = '\0';
22+
strncpy(output[i], s.c_str(), len);
23+
i++;
24+
}
25+
26+
*argc = static_cast<int>(sz);
27+
*argv = output;
28+
}
29+
30+
extern "C"
31+
JNIEXPORT jint JNICALL
32+
Java_com_viliussutkus89_pdf2htmlex_android_1sample_1app_MainActivity_call_1pdf2htmlEX(JNIEnv *env,
33+
jobject instance,
34+
jstring dataDir_,
35+
jstring tmpDir_,
36+
jstring inputFile_,
37+
jstring outputFile_) {
38+
const char *dataDir = env->GetStringUTFChars(dataDir_, 0);
39+
const char *tmpDir = env->GetStringUTFChars(tmpDir_, 0);
40+
const char *inputFile = env->GetStringUTFChars(inputFile_, 0);
41+
const char *outputFile = env->GetStringUTFChars(outputFile_, 0);
42+
43+
44+
std::vector<const std::string> args = {
45+
"libpdf2htmlEX.so",
46+
"--data-dir", dataDir,
47+
"--tmp-dir", tmpDir,
48+
inputFile, outputFile
49+
};
50+
51+
int argc;
52+
char ** argv;
53+
vector_to_char_pp(args, &argc, &argv);
54+
int retVal = pdf2htmlEX_main(argc, argv);
55+
for (int i = 0; i < argc; i++) {
56+
delete[] argv[i];
57+
}
58+
delete argv;
59+
60+
env->ReleaseStringUTFChars(dataDir_, dataDir);
61+
env->ReleaseStringUTFChars(tmpDir_, tmpDir);
62+
env->ReleaseStringUTFChars(inputFile_, inputFile);
63+
env->ReleaseStringUTFChars(outputFile_, outputFile);
64+
return retVal;
65+
}

0 commit comments

Comments
 (0)