Skip to content

Commit

Permalink
Merge pull request #43 from DevCrew-io/update-sdk
Browse files Browse the repository at this point in the history
Update Camera kit SDK to 1.36.0 & Configuration setup is updated as per new snapchat version.
  • Loading branch information
AliRehan-DevCrew authored Dec 4, 2024
2 parents 463116f + c11642e commit 631859b
Show file tree
Hide file tree
Showing 31 changed files with 155 additions and 196 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## 1.0.2
### Updated
* Update Camera kit SDK to 1.36.0
* Configuration setup is updated as per new snapchat version.

## 1.0.1
* Update Camera kit SDK to 1.31.0

## 1.0.0
* Fix dart formatting warnings for pub points
* Fix dart formatting warnings for pub points.

## 0.0.7
### Fixed
Expand Down
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For more information you can read the docs [Android](https://docs.snap.com/camer
#### CAUTION
**API Token** is different for **Production** and **Staging** Environment. A watermark will be applied to the camera view when using the Staging API token.

## Configuration
Once you have access to the account, locate your **groupIds** and **cameraKitApiToken**.

Now that you have obtained all your credentials, you can use it to initialize the Configuration class in your Flutter application as mentioned in the below section.
Expand All @@ -23,11 +24,24 @@ Now that you have obtained all your credentials, you can use it to initialize th
class Constants {
/// List of group IDs for Camera Kit
static const List<String> groupIdList = ['your-group-ids']; // TODO: Fill group IDs here
/// The API token for Camera Kit in the staging environment
static const cameraKitApiToken = 'your-api-token'; // TODO fill api token staging or production here
}
```

#### Android Setup
The easiest way to include this, is to define a <meta-data> tag in AndroidManifest.xml with a Camera Kit application ID value under <application> tag:

```dart
<application ...>
<meta-data android:name="com.snap.camerakit.app.id" android:value="" />
<meta-data android:name="com.snap.camerakit.api.token" android:value="" />
</application>
```

#### iOS Setup
Add `SCCameraKitClientID` (string), and set it to your application's Snap Kit App ID in your application's `Info.plist` file.

Add `SCCameraKitAPIToken` (string), and set it to your application's API Token in your application's `Info.plist` file.

**Note:** To use production api token, your camerakit app should be approved and live on snapchat developer portal.
Otherwise the app may cause `unauthorized` exception. [Read more](https://docs.snap.com/camera-kit/app-review/release-app) about submitting app for review

Expand Down Expand Up @@ -101,19 +115,12 @@ https://github.com/DevCrew-io/camerakit-flutter/assets/136708738/63eb485d-1998-4



## Set Configuration

You can set camerakit credentials by just calling setCredentials function. Before calling you need instance of CameraKitFlutterImpl, you only need to pass apiToken to configure camerakit flutter package. You don't need to set separate credentials for iOS and Android.

```dart
late final _cameraKitFlutterImpl = CameraKitFlutterImpl(cameraKitFlutterEvents: this);
_cameraKitFlutterImpl.setCredentials(apiToken: Constants.cameraKitApiToken);
```
## Access Camerakit in Flutter
### Load all lenses
You can access camerakit by just calling openCameraKit function with only the list of groupIds to load all lenses of given groups.
You can hide or show close button on camerakit screen by setting isHideCloseButton to true or false respectively.
```dart
late final _cameraKitFlutterImpl = CameraKitFlutterImpl(cameraKitFlutterEvents: this);
_cameraKitFlutterImpl.openCameraKit(
groupIds: Constants.groupIdList,
isHideCloseButton: false,
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ android {
dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.mockito:mockito-core:5.0.0'
implementation "com.snap.camerakit:support-camera-activity:1.31.0"
implementation "com.snap.camerakit:support-camera-activity:1.36.0"
implementation 'com.google.code.gson:gson:2.8.8' // Use the latest version available
}

Expand Down
7 changes: 7 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import java.io.Closeable
class CamerakitFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
PluginRegistry.ActivityResultListener {

private val CHANNEL = "camerakit_flutter"
private lateinit var context: Context
private lateinit var activity: Activity
private lateinit var cameraKitSession: Session
Expand All @@ -50,45 +49,27 @@ class CamerakitFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,

private val cameraKitRequestCode = 200;
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, CHANNEL)
channel = MethodChannel(flutterPluginBinding.binaryMessenger, Configuration.getInstance().channelName)
channel.setMethodCallHandler(this)
context = flutterPluginBinding.applicationContext


}

private fun isInvalidApiToken(): Boolean {
if( Configuration.getInstance().apiToken.isNullOrBlank() || Configuration.getInstance().apiToken == "your-api-token" ) {
Log.d("CameraKit-Flutter", "Your api token is invalid")
return true
}
return false
}

/// onMethodCall function handles incoming method calls from Dart and performs actions accordingly.
/// The 'call' parameter contains information about the method called, and 'result' is used to send back the result.
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
when (call.method) {
InputMethods.SET_CAMERA_KIT_CREDENTIALS -> {
// Handle setting Camera Kit credentials.
val arguments: Map<String, Any>? = call.arguments()
if (arguments != null) {
// Create a Configuration object from the provided arguments.
Configuration.createFromMap(arguments)
}
}

InputMethods.OPEN_SINGLE_LENS -> {
val arguments: Map<String, Any>? = call.arguments()
val lensId = arguments?.get("lensId") as? String ?: ""
val groupId = arguments?.get("groupId") as? String ?: ""
Configuration.getInstance().isHideCloseButton = arguments?.get("isHideCloseButton") as? Boolean ?: false

if (isInvalidApiToken() || lensId.isNullOrBlank() || groupId.isNullOrBlank()) return
if (lensId.isNullOrBlank() || groupId.isNullOrBlank()) return

val intent = ARCameraActivity.Capture.createIntent(
context, CameraActivity.Configuration.WithLens(
cameraKitApiToken = Configuration.getInstance().apiToken,
lensId = lensId,
lensGroupId = groupId,
)
Expand All @@ -101,11 +82,10 @@ class CamerakitFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
val groupIds = arguments?.get("groupIds") as? List<String> ?: emptyList();
Configuration.getInstance().isHideCloseButton = arguments?.get("isHideCloseButton") as? Boolean ?: false

if (isInvalidApiToken() || groupIds.isEmpty()) return
if (groupIds.isEmpty()) return

val intent = ARCameraActivity.Capture.createIntent(
context, CameraActivity.Configuration.WithLenses(
cameraKitApiToken = Configuration.getInstance().apiToken,
lensGroupIds = groupIds.toSet()
)
)
Expand All @@ -117,9 +97,7 @@ class CamerakitFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
val groupIds = arguments?.get("groupIds") as? List<String> ?: emptyList();

// Handle getting group lenses.
cameraKitSession = Session(activity) {
apiToken(Configuration.getInstance().apiToken)
}
cameraKitSession = Session(activity)
lensRepositorySubscription = cameraKitSession.lenses.repository.observe(
LensesComponent.Repository.QueryCriteria.Available(groupIds.toSet())
) { resultLenses ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ package com.camerakit.camerakit_flutter
// Copyright © 2023 DevCrew I/O
//
class Configuration private constructor(
val apiToken: String,
var isHideCloseButton: Boolean
var channelName: String = "camerakit_flutter",
var isHideCloseButton: Boolean = false
) {

companion object {
private var instance: Configuration? = null

fun getInstance() = instance
?: throw IllegalStateException("please set configuration with Configuration.createFromMap(...) method")
fun getInstance(): Configuration {
if (instance == null) {
instance = Configuration()
}


fun createFromMap(arguments: Map<String, Any>): Configuration {
instance = Configuration(
apiToken = arguments["token"] as? String ?: "",
isHideCloseButton = false,
)
return instance!!
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ object InputMethods: InvokeMethods {
const val GET_GROUP_LENSES = "getGroupLenses"
const val OPEN_CAMERA_KIT = "openSnapCameraKit"
const val OPEN_SINGLE_LENS = "openSingleLens"
const val SET_CAMERA_KIT_CREDENTIALS = "setCameraKitCredentials"

}

Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (flutterVersionName == null) {
android {
namespace "com.camerakit.camerakit_flutter_example"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
ndkVersion = "27.0.12077973"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
3 changes: 3 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
android:theme="@style/AppCompat"
android:icon="@mipmap/ic_launcher">

<meta-data android:name="com.snap.camerakit.app.id" android:value="" />
<meta-data android:name="com.snap.camerakit.api.token" android:value="" />

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.android.tools.build:gradle:8.7.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
3 changes: 3 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
4 changes: 3 additions & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
29 changes: 15 additions & 14 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
PODS:
- camerakit_flutter (1.0.0):
- camerakit_flutter (1.0.2):
- Flutter
- SCCameraKit (~> 1.31.0)
- SCCameraKitReferenceUI (~> 1.31.0)
- SCCameraKit (~> 1.36.0)
- SCCameraKitReferenceUI (~> 1.36.0)
- Flutter (1.0.0)
- integration_test (0.0.1):
- Flutter
- SCCameraKit (1.31.0)
- SCCameraKitReferenceUI (1.31.0):
- SCCameraKit (~> 1.31.0)
- SCCameraKit (1.36.1)
- SCCameraKitReferenceUI (1.36.1):
- SCCameraKit (~> 1.36.1)
- video_player_avfoundation (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- camerakit_flutter (from `.symlinks/plugins/camerakit_flutter/ios`)
- Flutter (from `Flutter`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/ios`)
- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`)

SPEC REPOS:
trunk:
Expand All @@ -31,16 +32,16 @@ EXTERNAL SOURCES:
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
video_player_avfoundation:
:path: ".symlinks/plugins/video_player_avfoundation/ios"
:path: ".symlinks/plugins/video_player_avfoundation/darwin"

SPEC CHECKSUMS:
camerakit_flutter: 036d39972cbacf8c8ace5c3a4192e506e4280605
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
camerakit_flutter: df8f6df07fd3fe870951695841ece0cef4b30be1
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
integration_test: 13825b8a9334a850581300559b8839134b124670
SCCameraKit: 13bd1ba528ce64057365b6ad631369aed39d9e70
SCCameraKitReferenceUI: ed241400d908e63c07bc07a08e741bb2eebfc8b0
video_player_avfoundation: 81e49bb3d9fb63dccf9fa0f6d877dc3ddbeac126
SCCameraKit: 9fe4e79e1b85ce215e900b36dcae55b395105d3c
SCCameraKitReferenceUI: 2c41a8bcdcef212c3ddf7d8ac913fa0aac5a51bf
video_player_avfoundation: 7c6c11d8470e1675df7397027218274b6d2360b3

PODFILE CHECKSUM: a57f30d18f102dd3ce366b1d62a55ecbef2158e5

COCOAPODS: 1.14.3
COCOAPODS: 1.16.2
2 changes: 1 addition & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1510;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 4 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>SCCameraKitAPIToken</key>
<string></string>
<key>SCCameraKitClientID</key>
<string></string>
</dict>
</plist>
3 changes: 0 additions & 3 deletions example/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
class Constants {
/// List of group IDs for Camera Kit
static const List<String> groupIdList = ['your-group-ids']; // TODO: Fill group IDs here

/// The API token for Camera Kit in the staging environment
static const cameraKitApiToken = 'your-api-token'; // TODO fill api token staging or production here
}
2 changes: 0 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class _MyAppState extends State<MyApp> implements CameraKitFlutterEvents {
@override
void initState() {
super.initState();

_cameraKitFlutterImpl.setCredentials(apiToken: Constants.cameraKitApiToken);
}

// Platform messages are asynchronous, so we initialize in an async method.
Expand Down
Loading

0 comments on commit 631859b

Please sign in to comment.