7.2 KiB
Development Setup Guide
This guide will help you set up the My ActivityPub project for development.
Prerequisites
Required Software
- Android Studio
- Version: Hedgehog (2023.1.1) or newer
- Download: https://developer.android.com/studio
- Java Development Kit (JDK)
- Version: JDK 11 or higher
- Android Studio includes a JDK, or download from: https://adoptium.net/
- Git
- Version: Latest stable
- Download: https://git-scm.com/downloads
- Android SDK
- API Level 24 (Android 7.0) minimum
- API Level 35 (Android 14) target
- Installed via Android Studio SDK Manager
Recommended Tools
- Android Device or Emulator for testing
- ADB (Android Debug Bridge) - included with Android Studio
- Gradle - wrapper included in project
Project Setup
1. Clone the Repository
git clone https://github.com/your-username/MyActivityPub.git
cd MyActivityPub
2. Open in Android Studio
- Launch Android Studio
- Select File > Open
- Navigate to the cloned repository
- Click OK
3. Gradle Sync
Android Studio will automatically trigger a Gradle sync. If not:
- Click File > Sync Project with Gradle Files
- Wait for sync to complete
- Resolve any errors if they appear
4. Install Dependencies
The Gradle build system will automatically download all dependencies:
- Kotlin standard library
- Jetpack Compose libraries
- Retrofit for networking
- Coil for image loading
- Material 3 components
5. Configure Build Variants
- Click Build > Select Build Variant
- Choose
debugfor development - Use
releasefor production builds
Building the Project
Debug Build
# From command line
./gradlew assembleDebug
# Output location
app/build/outputs/apk/debug/app-debug.apk
Release Build
# Create signed release APK
./gradlew assembleRelease
# Output location
app/build/outputs/apk/release/app-release.apk
Running the App
On Physical Device
- Enable Developer Options on your Android device:
- Go to Settings > About Phone
- Tap Build Number 7 times
- Enable USB Debugging:
- Go to Settings > Developer Options
- Enable USB Debugging
- Connect device via USB
- In Android Studio:
- Click Run > Run 'app'
- Or press Shift + F10
- Select your device
On Emulator
- Create an AVD (Android Virtual Device):
- Click Tools > Device Manager
- Click Create Device
- Select a device definition (e.g., Pixel 6)
- Select system image (API 24+)
- Click Finish
- Run the app:
- Click Run > Run 'app'
- Select the emulator
Configuration
Gradle Properties
Edit gradle.properties to configure build settings:
# Increase memory for large projects
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
# Enable parallel builds
org.gradle.parallel=true
# Enable configuration cache (Gradle 8.0+)
org.gradle.configuration-cache=true
API Configuration
To connect to a different Mastodon instance, edit MainActivity.kt:
val retrofit = Retrofit.Builder()
.baseUrl("https://your-instance.social/") // Change this
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
Troubleshooting
Common Issues
1. Gradle Sync Failed
Problem: "Could not download dependencies" Solutions:
# Clear Gradle cache
rm -rf ~/.gradle/caches/
./gradlew clean --no-daemon
# Or in Android Studio:
# File > Invalidate Caches > Invalidate and Restart
2. Build Failed with Memory Error
Problem: "Java heap space" or "OutOfMemoryError"
Solution: Increase memory in gradle.properties:
org.gradle.jvmargs=-Xmx4096m
3. SDK Not Found
Problem: "Failed to find target with hash string 'android-35'" Solution:
- Open SDK Manager: Tools > SDK Manager
- Install Android 14.0 (API 35)
- Sync Gradle files
4. Emulator Won't Start
Problem: Emulator crashes or doesn't start Solutions:
- Enable virtualization in BIOS/UEFI
- Install HAXM (Intel) or WHPX (Windows)
- Reduce emulator RAM allocation
- Use ARM system image instead of x86
5. App Crashes on Launch
Problem: App crashes immediately after launch Solutions:
- Check Logcat for error messages
- Verify internet permission in manifest
- Clear app data:
adb shell pm clear com.manalejandro.myactivitypub
Debugging
View Logs
# View all logs
adb logcat
# Filter by app
adb logcat | grep MyActivityPub
# Filter by tag
adb logcat -s TimelineViewModel
# Clear logs
adb logcat -c
Debug in Android Studio
- Set breakpoints in code
- Click Run > Debug 'app'
- Interact with app
- Use debug panel to inspect variables
IDE Configuration
Android Studio Settings
Recommended settings for development:
- Code Style:
- Settings > Editor > Code Style > Kotlin
- Set from: Kotlin style guide
- Auto Import:
- Settings > Editor > General > Auto Import
- Enable Add unambiguous imports on the fly
- Enable Optimize imports on the fly
- Live Templates:
- Settings > Editor > Live Templates
- Useful templates:
comp,vm,repo
- Version Control:
- Settings > Version Control > Git
- Configure your Git author info
Useful Plugins
- Rainbow Brackets: Colorize bracket pairs
- GitToolBox: Enhanced Git integration
- Key Promoter X: Learn keyboard shortcuts
- ADB Idea: Quick ADB commands
- .ignore: Manage .gitignore files
Testing Setup
Unit Tests
# Run all unit tests
./gradlew test
# Run tests for specific variant
./gradlew testDebugUnitTest
Instrumented Tests
# Run on connected device/emulator
./gradlew connectedAndroidTest
Test Coverage
# Generate coverage report
./gradlew jacocoTestReport
# View report at:
# app/build/reports/jacoco/test/html/index.html
Code Quality
Lint Checks
# Run lint
./gradlew lint
# View report at:
# app/build/reports/lint-results.html
Static Analysis
# Run detekt (if configured)
./gradlew detekt
Environment Variables
For sensitive data, use local environment variables:
# In ~/.bashrc or ~/.zshrc
export MASTODON_BASE_URL="https://mastodon.social/"
export API_KEY="your-api-key"
Access in Gradle:
android {
defaultConfig {
buildConfigField("String", "BASE_URL", "\"${System.getenv("MASTODON_BASE_URL")}\"")
}
}
Next Steps
After setup:
- Read ARCHITECTURE.md to understand the codebase
- Check CONTRIBUTING.md for contribution guidelines
- Review API.md for API documentation
- Start coding! 🚀
Getting Help
If you encounter issues:
- Check this guide thoroughly
- Search existing Issues
- Check Stack Overflow
- Ask in Discussions
- Create a new issue with details