Release of Android platform development (Java API)


#4

Are there instructions on how to use a native Java library, rather than the one including the Android dependencies?

From looking at the code in https://github.com/maidsafe/safe_app_java under api, it isn’t obvious that there are any Android libraries needed. However, when I try to build the library, it is asking me for Android SDK, agreed Android licenses and so forth.

Ideally, I’d like to be able to use JitPack to just build a jar that I can use in my Java project, until there is any formal Maven Central package that I can include.

I understand that Android may be the destination, but core Java support should be on-route. Has anyone been experimenting with this?


#5

You can build just the native Java lib from the command line like:

gradlew :safe-app:download-nativelibs
gradlew :safe-app:build

The api and lib jars will be created in safe_app_java/api/build/libs and safe_app_java/lib/build/libs.
The shared native libs will be in safe_app_java/safe-app/.tempDownloads.


#6

Thanks, @ogrebgr - that is exactly what I needed! Are these things obvious from the build.gradle or some such? I’ve not really used gradle much in anger.


#7

More or less… I just had the experience from previous versions and the experiments with them.


#8

@Traktion @ogrebgr I’ve created a new topic with some desktop specific instructions and an example too :slight_smile:
https://forum.safedev.org/t/java-api-support-on-desktop-platforms/


#9

Hi all,

It’s been a little quiet on here for a little bit…

  • Is anyone struggling and need any help?
  • Is anyone working on something that they’d like to talk about?
  • Is anyone looking for some feedback on their DApp idea/concept/prototype?

David.


#10

I am working on proof-of-concept mail/chat app. Currently at the stage of creating simpler API around NativeBindings. Will need few more weekends until having something to show…


#11

nice… I look forward to seeing it when you are comfortable with it :smile:!


#12

Hi all - just working my way through the tutorial app. I keep getting stuck here. I’m guessing that when I was asked to include dependencies (alt-enter followed by a choice of two options) I picked the wrong one. I can’t see an obvious way back though. Bearing in mind that I haven’t the first clue what I’m doing, what’s the next step?


#13

You probably autoimported ContainerPermissions from safe_authenticator, not the regular. Go on top of the file, find import net.maidsafe.safe_authenticator.ContainerPermissions;, remove it, and then import the regular (i.e. the one without safe_authenticator in its name).


#14

Thanks @ogrebgr - got me onto the next stage at least. I’m now stuck here - lots of symbols can’t be resolved. I notice the connect() method takes different arguments in SafeTodoService.java template from @lionel.faber’s video (8:30, lower image) so presumably it’s been updated. Could that be the issue? I’ve tried clearing the cache and restarting - no joy.
Thanks for any help.



#15

Open build.gradle (app). There is:
mockImplementation ‘net.maidsafe:safe-app-android-dev:0.1.0-SNAPSHOT’
nonMockImplementation ‘net.maidsafe:safe-app-android:0.1.0-SNAPSHOT’

Hit Alt-Enter on each to be changed to latest version, sync and errors should be gone.


#16

I can’t find any mention of those items.

Here is app.build.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha09"
    }
}
apply plugin: 'com.android.application'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'checkstyle'
apply plugin: 'pmd'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "net.maidsafe.sample"
        minSdkVersion 24
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "app"
    productFlavors {
        mock {
            dimension "app"
        }
        nonMock {
            dimension "app"
        }
    }
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(include: ['*.aar'], dir: 'libs')
    implementation 'com.android.support:support-v4:28.0.0'
    mockImplementation 'net.maidsafe:safe-app-android-dev:0.1.0'
    nonMockImplementation 'net.maidsafe:safe-app-android:0.1.0'
    implementation "com.android.support:appcompat-v7:28.0.0"
    implementation "com.android.support:animated-vector-drawable:28.0.0"
    implementation "com.android.support:design:28.0.0"
    implementation "com.android.support:cardview-v7:28.0.0"
    implementation "com.android.support:recyclerview-v7:28.0.0"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.android.support:support-compat:28.0.0"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    def nav_version = "1.0.0-alpha09"
    implementation "android.arch.navigation:navigation-fragment:$nav_version"
    implementation "android.arch.navigation:navigation-ui:$nav_version"
    def lifecycle_version = "1.1.1"
    implementation "android.arch.lifecycle:extensions:$lifecycle_version"
}
task checkstyle(type: Checkstyle) {
    configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml")
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
}
task pmd(type: Pmd) {
    ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml")
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/ServicesTest.java'
    reports {
        xml.enabled = false
        html.enabled = true
    }
}
check.dependsOn('checkstyle')
check.dependsOn('pmd')

#17

Strange…

It seems that you are missing:

repositories {
    maven {
        url "https://oss.jfrog.org/artifactory/oss-snapshot-local/"
    }
}

from dependencies, i.e. add in before mockImplementation 'net.maidsafe:safe-app-android-dev:0.1.0'


#18

Hey @JPL. Looks like you’re updating the connect function in the SafeTodoService class. The code from the tutorial should go into the SafeApi class’ connect function.

Thanks for jumping in and helping @ogrebgr :slight_smile:

With regard to the dependencies, the SNAPSHOT libraries will contain the latest version of the code from the master branch. This is a pre-release that devs can try out before an official release of a new version on jcenter. So for example, if you raise a PR ( :wink: :wink: ) with a bug-fix / improvement that gets merged into the repo’s master branch, an updated version of the library will be available on the OSS-SNAPSHOT-LOCAL repository as safe-app-android:0.2.0-SNAPSHOT so that other devs can start trying it out before the official release on jcenter.

In @JPL’s case the dependencies are specified without the -SNAPSHOT prefix so the additional repo link will not be required.


#19

OK, getting there. One step at a time … Pretty sure I’ve updated the right class this time (doh), but I’m getting the ‘cannot resolve symbol’ error again.


#20

You’ll have to import the packages in this class too. An easy way is to add

import net.maidsafe.safe_app.*

along with the other imports :slight_smile:


#21

Yes that fixed it thanks! Apologies for the constant questions. I haven’t used Android Studio before and it’s a bit of a maze.


#22

OK, a fun build error to finish off :slightly_smiling_face: . The files all seem to be there. Any idea why it can’t install them? This is on clicking “Run”.

$ adb install-multiple -r -t /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_7.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_1.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_2.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_0.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/dep/dependencies.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_4.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_3.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/resources/instant-run/mock/debug/resources-mock-debug.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_5.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_6.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_9.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/split-apk/mock/debug/slices/slice_8.apk /media/user/KingstonSSD/safe-getting-started-android/app/build/intermediates/instant-run-apk/mock/debug/app-mock-debug.apk 
Error while Installing APKs

#23

My first guess is that you’re using an x86 emulator. The safe-app-android package will only support devices with x86_64 and armeabi-v7a.

When creating an emulator, please make sure that you choose a system image with x86_64 ABI.