Skip to content

Commit

Permalink
Merge pull request #79 from cconlon/androidProject
Browse files Browse the repository at this point in the history
Sample Android project, Android Gradle GitHub Action, and gradle build fixes
  • Loading branch information
JacobBarthelmeh authored Oct 11, 2024
2 parents ce4a5b9 + 14301a1 commit ddddfc6
Show file tree
Hide file tree
Showing 97 changed files with 3,823 additions and 1,336 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/android_gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Android Gradle Build test logic

on:
workflow_call:
inputs:
os:
required: true
type: string
jdk_distro:
required: true
type: string
jdk_version:
required: true
type: string

jobs:
build_wolfssljni:
runs-on: ${{ inputs.os }}
steps:
- name: Clone wolfcrypt-jni
uses: actions/checkout@v4

# Clone native wolfSSL
- name: Clone native wolfSSL
uses: actions/checkout@v4
with:
repository: 'wolfssl/wolfssl'
path: IDE/Android/app/src/main/cpp/wolfssl

# Copy options.h.in to blank options.h
- name: Create blank options.h
run: cp IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h.in IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h

# Setup Java
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: ${{ inputs.jdk_distro }}
java-version: ${{ inputs.jdk_version }}

# Gradle assembleDebug
- name: Gradle assembleDebug
run: cd IDE/Android && ls && ./gradlew assembleDebug

# Gradle assembleDebugUnitTest
- name: Gradle assembleDebugUnitTest
run: cd IDE/Android && ls && ./gradlew assembleDebugUnitTest

# Gradle assembleDebugAndroidTest
- name: Gradle assembleDebugAndroidTest
run: cd IDE/Android && ls && ./gradlew assembleDebugAndroidTest

15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,18 @@ jobs:
jdk_version: ${{ matrix.jdk_version }}
wolfssl_configure: ${{ matrix.wolfssl_configure }}

# ----------------------- Android Gradle build ------------------------
# Run Android gradle build over PR code, only running on Linux with one
# JDK/version for now.
android-gradle:
strategy:
matrix:
os: [ 'ubuntu-latest' ]
jdk_version: [ '21' ]
name: Android Gradle (${{ matrix.os }} Zulu JDK ${{ matrix.jdk_version }})
uses: ./.github/workflows/android_gradle.yml
with:
os: ${{ matrix.os }}
jdk_distro: "zulu"
jdk_version: ${{ matrix.jdk_version }}

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ rpm/spec
*.rpm
wolfcrypt*.tar.gz

# Android
IDE/Android/.idea/deploymentTargetDropDown.xml
IDE/Android/app/.cxx/
IDE/Android/app/src/main/cpp/wolfssl

# Windows
IDE/WIN/.vs
IDE/WIN/wolfcryptjni.vcxproj.user
Expand Down
13 changes: 13 additions & 0 deletions IDE/Android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
3 changes: 3 additions & 0 deletions IDE/Android/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions IDE/Android/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions IDE/Android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions IDE/Android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions IDE/Android/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions IDE/Android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions IDE/Android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions IDE/Android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Android Studio Example Project

This is an example Android Studio project file for wolfcrypt-jni / wolfJCE.
This project should be used for reference only.

Tool and version information used when testing this project:

- Ubuntu 20.04.3 LTS
- Android Studio Chipmunk 2021.2.1
- Android Gradle Plugin Version: 4.2.2
- Gradle Version: 7.1.3
- API 30: Android 11
- Emulator: Pixel 5 API 31

The following sections outline steps required to run this example on an
Android device or emulator.

## 1. Add Native wolfSSL Library Source Code to Project

This example project is already set up to compile and build the native
wolfSSL library source files, but the wolfSSL files themselves have not been
included in this package. You must download or link an appropriate version
of wolfSSL to this project using one of the options below.

The project looks for the directory
`wolfcrypt-jni/IDE/Android/app/src/main/cpp/wolfssl` for wolfSSL source code.
This can added in multiple ways:

- OPTION A: Download the latest wolfSSL library release from www.wolfssl.com,
unzip it, rename it to `wolfssl`, and place it in the direcotry
`wolfcrypt-jni/IDE/Android/app/src/main/cpp/`.

```
$ unzip wolfssl-X.X.X.zip
$ mv wolfssl-X.X.X wolfcrypt-jni/IDE/Android/app/src/main/cpp/wolfssl
```

- OPTION B: Alternatively GitHub can be used to clone wolfSSL:

```
$ cd /IDE/Android/app/src/main/cpp/
$ git clone https://github.com/wolfssl/wolfssl
$ cp wolfssl/options.h.in wolfssl/options.h
```

- OPTION C: A symbolic link to a wolfssl directory on the system by using:

```
$ cd /IDE/Android/app/src/main/cpp/
$ ln -s /path/to/local/wolfssl ./wolfssl
```

## 2. Update Java Symbolic Links (Only applies to Windows Users)

The following Java source directory is a Unix/Linux symlink:

```
wolfcrypt-jni/IDE/Android/app/src/main/java/com/wolfssl
```

This will not work correctly on Windows, and a new Windows symbolic link needs
to be created in this location. To do so:

1) Open Windows Command Prompt (Right click, and "Run as Administrator")
2) Navigate to `wolfcrypt-jni\IDE\Android\app\src\main\java\com`
3) Delete the existing symlink file (it shows up as a file called "wolfssl")

```
del wolfssl
```

4) Create a new relative symbolic link with `mklink`:

```
mklink /D wolfssl ..\..\..\..\..\..\..\src\java\com\wolfssl\
```

## 3. Import and Build the Example Project with Android Studio

1) Open the Android Studio project by double clicking on the `Android` folder
in wolfcrypt-jni/IDE/. Or, from inside Android Studio, open the `Android`
project located in the wolfcrypt-jni/IDE directory.

2) Build the project and run MainActivity from app -> java/com/example.wolfssl.
This will ask for permissions to access the certificates in the /sdcard/
directory and then print out the server certificate information on success.

## Support

Please contact wolfSSL support at [email protected] with any questions or
feedback.

1 change: 1 addition & 0 deletions IDE/Android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions IDE/Android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apply plugin: 'com.android.application'

android {
compileSdk 33
defaultConfig {
applicationId "com.example.wolfssl"
/* Min SDK should stay at 24 to detect if we try to use newer APIs
* than were available in that Android SDK. We have users who are still
on SDK 24 (ref ZD 18311) */
minSdkVersion 24
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
sourceSets {
main.java.srcDirs += '../../../src/main/java'
test.java.srcDirs += '../../../src/main/test'
}
namespace 'com.example.wolfssl'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
21 changes: 21 additions & 0 deletions IDE/Android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Loading

0 comments on commit ddddfc6

Please sign in to comment.