This repository is not maintained anymore. To create awesome Android apps on Iroha, please use Java library. It is compatable with Android and is carefully maintained.
The library, in essence, is a set of Java interfaces and binary libraries compiled for different architectures. Supported architectures are arm, x86, x86_64.
There are two ways to get Iroha library for Android:
Grab via Gradle (see details in the section Importing the Library from jcenter)
implementation 'jp.co.soramitsu.iroha.android:iroha-android-bindings:+'
Compile the library on your own.
Both options are described in the following sections.
The guide was tested on systems running Ubuntu 16.04 and macOS.
Android NDK
Please download and unpack NDK to any suitable folder.
automake
sudo apt install automake
automake --version
# automake (GNU automake) 1.15
bison
sudo apt install bison
bison --version
# bison (GNU Bison) 3.0.4
cmake
Minimum required version is 3.8, but we recommend to install the latest available version (3.10.3 at the moment).
Since Ubuntu repositories contain unsuitable version of cmake, you need to install the new one manually. Here is how to build and install cmake from sources.
wget https://cmake.org/files/v3.10/cmake-3.10.3.tar.gz
tar -xvzf cmake-3.10.3.tar.gz
cd cmake-3.10.3/
./configure
make
sudo make install
cmake --version
# cmake version 3.10.3
All you need now is to download build script android-build.sh
to any
empty folder and launch it there.
Launch parameters are listed in the table below.
Position | Required | Parameter name | Description | Possible Values |
---|---|---|---|---|
1 | Yes | Platform name | Name of the target platform for binary part of the library. | arm64-v8a , armeabi-v7a armeabi , x86 , x86_64 |
2 | Yes | *Android API Level | API level supported by your NDK. See the link under the table for details. | 27 for android-ndk-r16b |
3 | Yes | Android NDK Path | Full path to unpacked NDK. Please ensure that path does not contain spaces. | /home/user/lib/android-ndk-r16b |
4 | Yes | Java Package Name | Package name that will be used for Java interfaces generation. Note that the binary also depends on chosen package name. | jp.co.soramitsu.iroha.android |
5 | No | Build Type | Defines build mode of binary part of the library. Release is the default option. | Debug or Release |
Please use the same root part of Java package name for library build as
you use for your Android project. For example, your project is located
in a package called com.mycompany.androidapp
, so please consider to
build the library in a package, which name starts with
com.mycompany.androidapp
(e.g. com.mycompany.androidapp.iroha
).
A couple of launch commands examples:
# build Java bindings and binary library for arm64-v8a in Release mode
./android-build.sh arm64-v8a 27 /home/user/lib/android-ndk-r16b com.mycompany.iroha
# build Java bindings and binary library for x86 in Debug mode
./android-build.sh x86 27 /home/user/lib/android-ndk-r16b com.mycompany.iroha Debug
Build artefacts will be collected in lib
directory near the script
android-build.sh
. There will be two files - an archive bindings.zip
and libirohajava.so
.
The easiest way to use Irohalib for Android is to import the library dependency from jcenter.
All you need to do is a simple set of four steps:
Add to your build.gradle
file the following line:
implementation 'jp.co.soramitsu.iroha.android:iroha-android-bindings:+'
Copy the latest version of *.proto
files from develop
branch of
Iroha [repository] into app/src/main/proto/
folder inside your
project in Android Studio.
The resulting directory structure should look like as follows:
app
└── src
└── main
└── proto
├── google
│ └── protobuf
│ └── empty.proto
├── block.proto
├── commands.proto
├── endpoint.proto
├── loader.proto
├── ordering.proto
├── primitive.proto
├── proposal.proto
├── queries.proto
├── responses.proto
└── yac.proto
Create additional directories app/src/main/proto/google/protobuf/
and place there a file called empty.proto
with the following
contents:
syntax = "proto3";
package google.protobuf;
option java_package = "com.google.protobuf"; option java_outer_classname = "EmptyProto"; option java_multiple_files = true;
message Empty { }
4. Add `protobuf` and `grpc` dependecies and protobuf configuration
block into your `buld.gradle` file.
```groovy
apply plugin: 'com.google.protobuf'
dependencies {
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation 'io.grpc:grpc-core:1.8.0'
implementation 'io.grpc:grpc-stub:1.8.0'
implementation 'io.grpc:grpc-okhttp:1.8.0'
implementation('io.grpc:grpc-protobuf-lite:1.8.0') {
// Otherwise Android compile will complain "Multiple dex files define ..."
exclude module: "protobuf-lite"
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.5.1-1'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.10.0'
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
option 'generate_equals=true'
}
}
}
}
}
.java
files
from bindings.zip
archive. For example, the path could be
app/src/main/java/com/mycompany/iroha
if you built the library
with com.mycompany.iroha
package name.app/src/main/jniLibs/<platform>
where
<platform>
is the name of target platform (e.g. arm64-v8a
). Put
there libirohajava.so
. Repeat this step for all required platforms
(in this case you need to build the library for each platform).Repeat steps 2-4 from the previous section [Importing the Library from jcenter].
Explore sample
package to view sample application.
Copyright 2018 Soramitsu Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.