Skip to content

Android Integration

Recommended: the Alphyn CLI. alphyn-cli integrate --android-api-key <key> wires the SDK dependency, initialization, and the build registration hook automatically. The SDK (com.byterialab:alphyn-sdk) resolves from the Alphyn package registry at build time, so set your app API key in the build environment; see SDK Registry Access:

Terminal window
export ALPHYN_REGISTRY_KEY=<YOUR_APP_API_KEY>

Your app module only needs the standard SDK levels:

android {
compileSdk 35
defaultConfig {
minSdk 26
targetSdk 35
}
}

Offline (manual): if your build cannot reach the registry, download the self-contained AAR from your app’s SDK Downloads page in the Alphyn dashboard, place it under app/libs/, and declare it as a local file dependency instead:

dependencies {
implementation(files("libs/alphyn-sdk-<version>.aar"))
}

The SDK ships native libraries for arm64-v8a, armeabi-v7a, and x86_64; no ABI filter configuration is needed. The SDK links its C++ runtime statically and ships no shared libc++_shared.so, so no pickFirst rule is required for it.

ProGuard / R8:

The AAR ships its own consumer ProGuard rules, which R8 applies to your app automatically - no manual rules are required. If your build pipeline strips consumer rules, the equivalent rules are:

# Alphyn SDK
-keep class com.byteria.sdk.** { *; }
-keep @androidx.annotation.Keep class * { *; }
-keepclassmembers class * {
@androidx.annotation.Keep <methods>;
}

Parameters:

  • Context: Application context (required)
  • Application Key (optional second parameter): a development-only debug hash obtained from the Alphyn Portal. Do not pass it in production - production apps initialize keyless, and the app’s attestation identity is the SHA-256 of its signing certificate.

Initialization Example:

public class ByteriaApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize as early as possible
try {
AlphynSDK.initialize(this);
} catch (IllegalArgumentException e) {
Log.e("Byteria", "Invalid parameters: " + e.getMessage());
} catch (Exception e) {
Log.e("Byteria", "Initialization failed: " + e.getMessage());
}
}
}

Best Practices: !!! note - Initialize in Application.onCreate() for best performance - Always handle IllegalArgumentException for invalid parameters - Check initialization status with AlphynSDK.isInitialized()

Complete Listener Implementation:

private void setupSecurityListener() {
AlphynSecurityListener listener = new AlphynSecurityListener() {
@Override
public void onSuccess(AlphynCallbackResult result) {
switch (result.getOperationType()) {
case INITIALIZATION:
handleInitializationSuccess(result);
break;
case SECURITY_SCAN:
handleScanSuccess(result);
break;
case SCAN_RESPONSE:
handleScanResponse(result);
break;
case NETWORK:
// Network events are informational only - SDK handles automatically
Log.d("Byteria", "Network: " + result.getOriginalEventType());
break;
case STORAGE:
// Storage events are informational only - SDK handles automatically
Log.d("Byteria", "Storage: " + result.getOriginalEventType());
break;
}
}
@Override
public void onFailure(AlphynCallbackResult result) {
Log.w("Byteria", String.format("Operation failed: %s - %s",
result.getOperationType(), result.getMessage()));
// Handle specific failure types
if (result.getOriginalEventType() == AlphynEventType.INIT_FAILED) {
// Critical failure - app cannot continue securely
handleCriticalFailure();
}
}
@Override
public void onThreatDetected(AlphynCallbackResult result) {
Log.w("Byteria", "Security threat: " + result.getMessage());
// Implement threat response based on your security policy
switch (result.getOriginalEventType()) {
case THREAT_DETECTED:
handleGenericThreat(result);
break;
default:
handleUnknownThreat(result);
break;
}
}
};
AlphynSDK.addSecurityListener(listener);
}

Event Processing Example:

private void handleInitializationSuccess(AlphynCallbackResult result) {
if (result.getOriginalEventType() == AlphynEventType.FIRST_INIT) {
Log.i("Byteria", "First time initialization completed");
// Perform first-time setup
} else if (result.getOriginalEventType() == AlphynEventType.INIT_COMPLETE) {
Log.i("Byteria", "SDK ready for use");
// Continue with normal app flow
}
}
private void handleScanSuccess(AlphynCallbackResult result) {
if (result.isScanResponse()) {
AlphynScanResult scanResult = result.getScanResult();
Log.i("Byteria", "Scan completed: " + scanResult.getDisplayName());
switch (scanResult) {
case TRUSTED:
Log.i("Byteria", "Application is trusted ✅");
break;
case FLAGGED:
Log.w("Byteria", "Application flagged for review ⚠️");
handleFlaggedResult();
break;
case UNTRUSTED:
Log.e("Byteria", "Application is untrusted 🚨");
handleUntrustedResult();
break;
}
}
}