Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Painless Libraries - Londroid April 2019

Painless Libraries - Londroid April 2019

Sérgio Marques Moura

April 16, 2019
Tweet

More Decks by Sérgio Marques Moura

Other Decks in Programming

Transcript

  1. onfido-android-sdk ├── build.gradle ├── gradle.properties ├── proguard-rules.pro ├── src ├──

    main │ ├── AndroidManifest.xml │ ├── java │ └── res └── test
  2. onfido-android-sdk └── src ├── main └── res ├── drawable ├──

    logo.xml ├── layout ├── activity_camera.xml app └── src ├── main └── res ├── drawable ├── logo.xml ├── layout ├── activity_camera.xml
  3. onfido-android-sdk app activity_camera.xml activity_camera.xml <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.onfido.android.sdk.capture.ui.camera.CameraView android:id="@+id/cameraView"

    android:layout_width="match_parent" android:layout_height="match_parent"/> ... </androidx.coordinatorlayout.widget.CoordinatorLayout> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/logo"/> ... </androidx.coordinatorlayout.widget.CoordinatorLayout> import kotlinx.android.synthetic.main.activity_camera.* cameraView.start() java.lang.NoSuchFieldError: com.onfido.android.sdk.capture.R$id.cameraView
  4. • android { /* Enables IDE warning if non-prefixed resource

    is defined. Code still compiles. Allowed names: - onfidoResource - onfido_resource - OnfidoResource */ resourcePrefix 'onfido' } • lintOptions { lintConfig rootProject.file("lint-rules.xml") abortOnError true } lint-rules-xml <lint> <issue id="ResourceName" severity="error" /> ... <issue id="NewApi" severity="warning" /> <issue id="MissingTranslation" severity="warning" /> </lint> ./gradlew onfido-android-sdk:lint
  5. • ◦ ◦ ▪ ◦ ▪ ▪ dependencies { implementation

    "com.onfido.sdk.capture:onfido-capture-sdk:4.8.0" } ./gradlew app:assembleRelease; ls -lh app/build/outputs/apk/release/
  6. • ◦ ◦ // host application build.gradle splits { abi

    { enable true reset() include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' universalApk true //generate an additional APK that contains all the ABIs } } AndroidX build artifacts androidx.core:core:1.0.0 androidx.recyclerview:recyclerview:1.0.0 androidx.constraintlayout:constraintlayout:1.0.0 androidx.lifecycle:lifecycle-livedata:1.0.0 dependencies { implementation 'com.onfido.sdk.capture:onfido-capture-sdk:4.8.0' // OR implementation 'com.onfido.sdk.capture:onfido-capture-sdk-core:4.8.0' (-48% size) }
  7. • // library implementation 'com.onfido:sample-lib:4.0.0' // app implementation 'com.onfido:sample-lib:4.0.0' ◦

    ▪ ◦ ▪ ▪ // library implementation 'com.onfido:sample-lib:4.0.0' // app implementation 'com.onfido:sample-lib:3.0.0'
  8. class MyApplication : Application() { override fun onCreate() { super.onCreate()

    AnalyticsLib.init(this, "APP_TOKEN") SampleLib.init(this) } } • class SampleLib { companion object { @JvmStatic fun init(context: Context) { AnalyticsLib.init(context, "LIBRARY_TOKEN") } } } • AnalyticsLib • AnalyticsLib • AnalyticsLib fun track(eventName: String) { AnalyticsLib.getInstance().track(eventName) }
  9. • ◦ com.samplelib.AnalyticsLib -> com.onfido.samplelib.AnalyticsLib com.samplelib.AnalyticsLib.init(context, "TOKEN") =/= com.onfido.samplelib.AnalyticsLib.init(context, "TOKEN")

    ◦ ◦ buildscript { dependencies { classpath 'ru.tinkoff.gradle:jarjar:1.1.0' classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.1' } } apply plugin: 'ru.tinkoff.gradle.jarjar' apply plugin: 'com.github.johnrengelman.shadow'
  10. jarJar { rules = [ “analyticsLib-$version.jar” : 'com.samplelib.** com.onfido.samplelib.@1' ]

    } dependencies { jarJar "com.samplelib:analytics:$version" implementation files("build/libs/analytics-$version.jar") } ◦ ◦ $version LICENSE.md
  11. onfido-android-sdk ├── build.gradle │ ├── bundled Proguard rules │ ├──

    resources name prefix │ ├── size impact │ ├── dependencies ├── src │ ├── main │ │ ├── AndroidManifest.xml
  12. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.onfido.android.sdk.capture"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CAMERA" /> <application>

    <activity android:name=".ui.OnfidoActivity" android:label="@string/onfido_activity_label" android:theme="@style/OnfidoActivityTheme" /> </application> </manifest> java.lang.IllegalArgumentException: either category or name must be provided.
  13. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.onfido.android.sdk.capture"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CAMERA" /> <application>

    <provider android:name=".OnfidoInitProvider" android:authorities="${applicationId}.onfidoinitprovider" android:enabled="true" android:exported="false"/> <activity android:name=".ui.OnfidoActivity" android:label="@string/onfido_activity_label" android:theme="@style/OnfidoActivityTheme" /> </application> </manifest>
  14. class MyApplication : Application() { override fun onCreate() { super.onCreate()

    SampleLib.init(this) } } class OnfidoInitProvider extends ContentProvider { override fun onCreate(): Boolean { SampleLib.init(context); return false; } } • ◦ ◦ • ◦ ◦
  15. onfido-android-sdk ├── build.gradle │ ├── bundled Proguard rules │ ├──

    resources name prefix │ ├── size impact │ ├── dependencies ├── src │ ├── main │ │ ├── AndroidManifest.xml ├── java ├── res
  16. • google-services.json ❖ firebase-auth ❖ firebase-messaging ❖ firebase-* { "project_info":

    { "project_number": "PROJECT_NUMBER", "firebase_url": "FIREBASE_URL", "project_id": "PROJECT_ID", "storage_bucket": "STORAGE_BUCKET" }, "client": [ { "client_info": { "mobilesdk_app_id": "MOBILE_SDK_APP_ID", "android_client_info": { "package_name": "PACKAGE_NAME" } }, "api_key": [ { "current_key": "KEY" } ], "services": { "analytics_service": { "status": 1 } } } ], "configuration_version": "CONFIGURATION_VERSION" } <string name="google_api_key">API_KEY</string> <string name="google_app_id">APPLICATION_ID</string> <string name="google_storage_bucket">STORAGE_BUCKET</string> <string name="firebase_database_url">FIREBASE_URL</string> <string name="project_id">PROJECT_ID</string> try { FirebaseApp.initializeApp(context, FirebaseOptions.Builder() .setApiKey("API_KEY") .setApplicationId("APPLICATION_ID") .build(), "PACKAGE_NAME") } catch (e: IllegalStateException) { // fallback code }