When integrating Antigravity into Unity or Flutter projects, many developers hit roadblocks early—SDK configuration complexity, authentication issues, and platform-specific constraints pile up quickly. This guide systematically addresses every error from initial SDK import through successful deployment on iOS and Android.
SDK Installation and Configuration Errors
Antigravity SDK setup differs per platform, and each has its own gotchas.
Adding Antigravity to Unity
Unity supports two SDK import methods: Asset Store and direct download.
Via Asset Store:
- Open Unity Editor → Window > Asset Store
- Search for "Antigravity SDK"
- Click "Import"
- Confirm that Assets/Plugins folder is created during import
Via Direct Download:
- Download the
.unitypackagefrom Antigravity's official site - In Unity, go to Assets > Import Package > Custom Package...
- Select the downloaded file
Configuration Error: API Key Not Recognized
// Wrong approach
AntigravityClient.Initialize("YOUR_API_KEY");
// ❌ Error: API key not foundIf you hit this, verify:
- Your API key has no surrounding whitespace
- Project Settings > Antigravity shows the key is saved
- Restart the Editor and clear cache: Edit > Clear All EditorPrefs (warning!)
Correct implementation:
// Correct approach
using Antigravity.SDK;
public class AntigravityManager : MonoBehaviour
{
void Start()
{
// Load API key from PlayerPrefs
var apiKey = PlayerPrefs.GetString("antigravity_api_key");
AntigravityClient.Initialize(apiKey);
// Or from environment variable
var envKey = System.Environment.GetEnvironmentVariable("ANTIGRAVITY_API_KEY");
AntigravityClient.Initialize(envKey);
}
}Adding Antigravity to Flutter
In Flutter, add the SDK via pubspec.yaml:
# pubspec.yaml
dependencies:
flutter:
sdk: flutter
antigravity_sdk: ^1.2.0 # Check for latest
http: ^0.13.0
provider: ^6.0.0Then run flutter pub get.
Common error:
Error: Could not resolve the SDK path for antigravity_sdk
Fix:
- Run
flutter clean - Run
flutter pub get - If still broken, delete
pubspec.lockand retry
API Connection and Authentication Issues
Once the SDK is imported, actual API calls often fail at the authentication layer.
Authentication Errors in Unity
// ❌ Common error scenario
try
{
var response = await AntigravityClient.Instance.CallAsync(new GenerateRequest
{
Prompt = "Hello Antigravity"
});
}
catch (AuthenticationException ex)
{
Debug.LogError($"Auth failed: {ex.Message}");
// Response: 401 Unauthorized
}Check these:
- API key validity: Verify in your dashboard
- Billing plan status: Is it active?
- Request headers: Does it include "Authorization: Bearer YOUR_API_KEY"?
Proper implementation:
public class AntigravityRequester : MonoBehaviour
{
private AntigravityClient _client;
void Awake()
{
_client = new AntigravityClient(new AntigravityConfig
{
ApiKey = PlayerPrefs.GetString("antigravity_api_key"),
Timeout = 30000, // 30 seconds
RetryCount = 3,
RetryDelay = 1000
});
}
public async Task<GenerateResponse> GenerateText(string prompt)
{
try
{
var request = new GenerateRequest
{
Prompt = prompt,
MaxTokens = 1000,
Temperature = 0.7f
};
var response = await _client.CallAsync(request);
return response;
}
catch (AuthenticationException)
{
Debug.LogError("API key is invalid or expired");
RefreshApiKey();
}
catch (RateLimitException)
{
Debug.LogWarning("Rate limit exceeded, waiting...");
await Task.Delay(5000); // Wait 5 seconds
}
}
private void RefreshApiKey()
{
// Fetch a fresh API key from your backend
}
}Authentication Errors in Flutter
Flutter typically manages auth via shared_preferences:
// lib/services/antigravity_service.dart
import 'package:antigravity_sdk/antigravity_sdk.dart';
import 'package:shared_preferences/shared_preferences.dart';
class AntigravityService {
late AntigravityClient _client;
late SharedPreferences _prefs;
Future<void> initialize() async {
_prefs = await SharedPreferences.getInstance();
final apiKey = _prefs.getString('antigravity_api_key') ?? '';
if (apiKey.isEmpty) {
throw Exception('API key not found in SharedPreferences');
}
_client = AntigravityClient(
apiKey: apiKey,
timeout: Duration(seconds: 30),
);
}
Future<String> generateText(String prompt) async {
try {
final response = await _client.generate(
prompt: prompt,
maxTokens: 1000,
temperature: 0.7,
);
return response.text;
} on AntigravityException catch (e) {
if (e.code == 'AUTH_ERROR') {
await _refreshApiKey();
rethrow;
} else if (e.code == 'RATE_LIMIT') {
await Future.delayed(Duration(seconds: 5));
return generateText(prompt);
}
rethrow;
}
}
Future<void> _refreshApiKey() async {
// Call backend to get fresh key, then save to SharedPreferences
}
}Build Errors and Dependency Resolution
The build phase is where most errors surface, and iOS/Android have different solutions.
iOS Build Failures
Common Xcode error:
ld: library not found for -lAntigravity
clang: error: linker command failed with exit code 1
Fix:
-
Reinstall Pods:
cd ios rm -rf Pods Podfile.lock pod install --repo-update cd .. -
Clear Xcode build cache:
rm -rf ~/Library/Developer/Xcode/DerivedData -
If still stuck, edit your Podfile:
# ios/Podfile target 'Runner' do pod 'AntigravitySDK', '~> 1.2.0' post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ '$(inherited)', 'ANTIGRAVITY_ENABLED=1' ] end end end end
Android Build Failures
Gradle sync often fails with:
Failed to resolve: com.antigravity:sdk:1.2.0
Fix:
-
Verify build.gradle:
// android/app/build.gradle dependencies { implementation 'com.antigravity:sdk:1.2.0' implementation 'com.google.code.gson:gson:2.8.9' } repositories { google() mavenCentral() maven { url 'https://maven.antigravity.com/releases' } } -
Clear Gradle cache:
cd android && ./gradlew clean && cd .. -
Check manifest (Android 12+):
<!-- android/app/src/main/AndroidManifest.xml --> <uses-permission android:name="android.permission.INTERNET" /> <queries> <package android:name="com.antigravity.*" /> </queries>
Code Generation Errors (Kotlin Multiplatform)
KMP builds sometimes fail with:
Error: Expected class declaration
Proper structure:
commonMain {
dependencies {
implementation("com.antigravity:sdk:1.2.0")
}
}
androidMain {
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
}
}
iosMain {
dependencies {
implementation("com.antigravity:sdk-ios:1.2.0")
}
}Platform-Specific Issues (iOS and Android)
iOS 14+: App Tracking Transparency
If Antigravity SDK accesses multiple domains, ATT (App Tracking Transparency) permission is required:
// ios/Runner/Runner/AppDelegate.swift
import AppTrackingTransparency
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
// Handle response
}
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}Android 9+: Network Security
Android 9+ blocks cleartext (non-HTTPS) by default:
<!-- android/app/src/main/res/xml/network_security_config.xml -->
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">api.antigravity.com</domain>
<pin-set>
<!-- Certificate pinning (optional) -->
</pin-set>
</domain-config>
</network-security-config>Reference in AndroidManifest.xml:
<!-- android/app/src/main/AndroidManifest.xml -->
<application
android:networkSecurityConfig="@xml/network_security_config"
...>
</application>Debugging and Logging
Identifying issues requires detailed logging output.
Logging in Unity
// Assets/Scripts/AntigravityDebugger.cs
public class AntigravityDebugger : MonoBehaviour
{
void Start()
{
AntigravityClient.EnableDebugLogging(true);
// Enable network tracing
System.Net.ServicePointManager.ServerCertificateValidationCallback =
(sender, cert, chain, sslPolicyErrors) =>
{
Debug.Log($"SSL Validation: {sslPolicyErrors}");
return true; // Dev only
};
}
}Logging in Flutter
// lib/services/logger.dart
import 'package:logger/logger.dart';
final logger = Logger(
printer: PrettyPrinter(
methodCount: 2,
errorMethodCount: 5,
),
);
// Usage
logger.d('API Call: ${request.toJson()}');
logger.w('Rate limit warning');
logger.e('Authentication error', error: exception);Advanced Debugging: Network Interception
For deep troubleshooting, intercept all network traffic. Both platforms support this:
// Flutter: Use Dio with logging interceptor
import 'package:dio/dio.dart';
final dio = Dio();
dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) {
logger.d('Request: ${options.method} ${options.path}');
return handler.next(options);
},
onResponse: (response, handler) {
logger.d('Response: ${response.statusCode}');
return handler.next(response);
},
onError: (error, handler) {
logger.e('Request error: ${error.message}');
return handler.next(error);
},
),
);// Unity: HTTP request debugging
using System.Net;
public class HttpDebugger
{
static HttpDebugger()
{
ServicePointManager.ServerCertificateValidationCallback =
(request, cert, chain, errors) =>
{
Debug.Log($"Certificate validation: {errors}");
return true; // Dev only!
};
}
}Looking back
Antigravity integration in Unity and Flutter typically breaks down into three stages: (1) SDK import and API key setup, (2) API authentication and connection, (3) build-time dependency resolution. Working systematically through each stage—using the checklists and code patterns in this guide—eliminates nearly all common errors.
Platform-specific constraints (iOS ATT, Android network security) are solvable when you understand the underlying mechanisms. Follow the implementation patterns here and your mobile development will be smooth and predictable. For more advanced patterns, check out Unity and Antigravity Fast Development Guide.
Further Reading
For hands-on SDK integration and native plugin patterns: