Skip to content

Commit 1b1f195

Browse files
committed
feat: switch from .env to hardcoded config and add build scripts for Android/iOS
1 parent 74331fb commit 1b1f195

File tree

4 files changed

+367
-81
lines changed

4 files changed

+367
-81
lines changed

android/README.md

Lines changed: 113 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A simple Android app that uses WebView to load the PDF Converter PWA from the pr
44

55
## Features
66

7-
- Loads the PWA from the URL specified in the project's root .env file
7+
- Loads the PWA from the URL specified in the Config.kt file
88
- Supports all PWA features through WebView
99
- Pull-to-refresh functionality
1010
- Handles back navigation within the WebView
@@ -16,63 +16,130 @@ A simple Android app that uses WebView to load the PDF Converter PWA from the pr
1616
- Minimum SDK: 21 (Android 5.0 Lollipop)
1717
- Target SDK: 33 (Android 13)
1818
- Kotlin 1.8.0+
19+
- JDK 11 or newer
20+
- Gradle 7.0.2 or newer
1921

20-
## Installation
22+
## Building and Running the App
2123

22-
1. Open the `PDFConverter` folder in Android Studio.
23-
2. Wait for Gradle sync to complete.
24-
3. Select your target device or emulator.
25-
4. Click the Run button or press `Shift+F10` to build and run the app.
24+
### Prerequisites
25+
26+
1. Install [Android Studio](https://developer.android.com/studio)
27+
2. Install the Android SDK through Android Studio's SDK Manager
28+
3. Make sure you have the required SDK platforms (API level 21-33) installed
29+
30+
### Building from Android Studio
31+
32+
1. Open Android Studio
33+
2. Select "Open an existing project"
34+
3. Navigate to the `android/PDFConverter` folder and click "Open"
35+
4. Wait for Gradle sync to complete
36+
5. Select your target device or emulator from the dropdown menu in the toolbar
37+
6. Click the Run button (green triangle) or press `Shift+F10` to build and run the app
38+
39+
### Building from Command Line
40+
41+
#### Using the Build Script (Recommended)
42+
43+
We've provided a convenient build script that handles the build process:
44+
45+
```bash
46+
cd android
47+
./build.sh
48+
```
49+
50+
This script will:
51+
1. Clean the project
52+
2. Build the debug APK
53+
3. Show the location and size of the generated APK
54+
4. Provide instructions for installing the APK on a device
55+
56+
#### Manual Build Process
57+
58+
If you prefer to build manually:
59+
60+
##### On macOS/Linux:
61+
62+
```bash
63+
cd android/PDFConverter
64+
./gradlew assembleDebug
65+
```
66+
67+
##### On Windows:
68+
69+
```bash
70+
cd android\PDFConverter
71+
gradlew.bat assembleDebug
72+
```
73+
74+
The APK file will be generated at `app/build/outputs/apk/debug/app-debug.apk`
75+
76+
### Installing the APK on a Device
77+
78+
#### Using ADB (Android Debug Bridge):
79+
80+
```bash
81+
adb install app/build/outputs/apk/debug/app-debug.apk
82+
```
83+
84+
#### Manually:
85+
86+
1. Transfer the APK file to your Android device
87+
2. On your device, navigate to the APK file and tap on it
88+
3. Follow the on-screen instructions to install the app
89+
90+
## Testing the App
91+
92+
### On an Emulator
93+
94+
1. In Android Studio, open the AVD Manager (Tools > AVD Manager)
95+
2. Create a new virtual device if you don't have one already
96+
3. Start the emulator
97+
4. Run the app on the emulator
98+
99+
### On a Physical Device
100+
101+
1. Enable Developer Options on your Android device:
102+
- Go to Settings > About phone
103+
- Tap on "Build number" 7 times until you see "You are now a developer"
104+
2. Enable USB Debugging:
105+
- Go to Settings > System > Developer options
106+
- Turn on "USB debugging"
107+
3. Connect your device to your computer via USB
108+
4. Allow USB debugging when prompted on your device
109+
5. In Android Studio, select your device from the dropdown menu
110+
6. Run the app
111+
112+
## Troubleshooting
113+
114+
### Common Issues
115+
116+
1. **Gradle sync failed**: Make sure you have the correct Gradle version and JDK installed
117+
2. **Device not recognized**: Check USB debugging is enabled and you have the proper USB drivers installed
118+
3. **App crashes on startup**: Check the logcat output in Android Studio for error details
119+
4. **WebView not loading**: Verify internet connectivity and that the URL in Config.kt is correct
120+
121+
### Debugging
122+
123+
1. In Android Studio, open the Logcat window (View > Tool Windows > Logcat)
124+
2. Filter the logs by "PDFConverter" to see app-specific logs
125+
3. Look for any error messages or exceptions
26126

27127
## Project Structure
28128

29129
- `MainActivity.kt`: Main activity with WebView implementation
30-
- `Config.kt`: Configuration class that reads from the .env file
31-
- `activity_main.xml`: Main layout with WebView and SwipeRefreshLayout
130+
- `Config.kt`: Configuration class that provides the API base URL
131+
- `activity_main.xml`: Main layout with WebView and bottom navigation bar
132+
- `bottom_nav_bar.xml`: Layout for the bottom navigation bar
32133
- `AndroidManifest.xml`: App configuration and permissions
33134
- `build.gradle`: Project and app-level build configurations
34135

35136
## Configuration
36137

37-
The app reads the PWA URL from the `API_BASE_URL` variable in the project's root `.env` file. This allows you to easily switch between different environments (development, staging, production) by modifying a single configuration file.
38-
39-
### How It Works
40-
41-
The `Config.kt` file reads the API_BASE_URL from the .env file:
42-
43-
```kotlin
44-
// In Config.kt
45-
object Config {
46-
// Default fallback URL
47-
private const val DEFAULT_API_BASE_URL = "https://profullstack.com/pdf"
48-
49-
// Get API base URL from .env file
50-
fun getApiBaseUrl(context: Context): String {
51-
// Try to find and parse the .env file
52-
// ...parsing logic...
53-
54-
// Return default URL if .env file not found or error occurs
55-
return DEFAULT_API_BASE_URL
56-
}
57-
}
58-
```
138+
The app uses a hardcoded URL in the `Config.kt` file. If you want to change the URL:
59139

60-
And the MainActivity uses this configuration:
61-
62-
```kotlin
63-
// In MainActivity.kt
64-
private lateinit var pwaUrl: String
65-
66-
override fun onCreate(savedInstanceState: Bundle?) {
67-
super.onCreate(savedInstanceState)
68-
setContentView(R.layout.activity_main)
69-
70-
// Get API base URL from .env file
71-
pwaUrl = Config.getApiBaseUrl(this)
72-
73-
// ...rest of the code...
74-
}
75-
```
140+
1. Open `app/src/main/java/com/profullstack/pdfconverter/Config.kt`
141+
2. Modify the `DEFAULT_API_BASE_URL` constant to point to your desired URL
142+
3. Rebuild the app
76143

77144
## Additional WebView Settings
78145

android/build.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Build script for PDF Converter Android app
4+
5+
# Set colors for output
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[1;33m'
8+
RED='\033[0;31m'
9+
NC='\033[0m' # No Color
10+
11+
echo -e "${YELLOW}Building PDF Converter Android App...${NC}"
12+
13+
# Check if we're in the right directory
14+
if [ ! -d "PDFConverter" ]; then
15+
echo -e "${RED}Error: PDFConverter directory not found!${NC}"
16+
echo -e "${YELLOW}Make sure you're running this script from the android directory.${NC}"
17+
exit 1
18+
fi
19+
20+
# Navigate to the project directory
21+
cd PDFConverter
22+
23+
# Check if gradlew exists and is executable
24+
if [ ! -x "gradlew" ]; then
25+
echo -e "${YELLOW}Making gradlew executable...${NC}"
26+
chmod +x gradlew
27+
fi
28+
29+
# Clean the project
30+
echo -e "${YELLOW}Cleaning project...${NC}"
31+
./gradlew clean
32+
33+
# Build debug APK
34+
echo -e "${YELLOW}Building debug APK...${NC}"
35+
./gradlew assembleDebug
36+
37+
# Check if build was successful
38+
if [ $? -eq 0 ]; then
39+
APK_PATH="app/build/outputs/apk/debug/app-debug.apk"
40+
41+
# Check if APK was generated
42+
if [ -f "$APK_PATH" ]; then
43+
echo -e "${GREEN}Build successful!${NC}"
44+
echo -e "${GREEN}APK generated at: ${YELLOW}$APK_PATH${NC}"
45+
46+
# Get APK size
47+
APK_SIZE=$(du -h "$APK_PATH" | cut -f1)
48+
echo -e "${GREEN}APK size: ${YELLOW}$APK_SIZE${NC}"
49+
50+
echo -e "\n${YELLOW}To install on a connected device:${NC}"
51+
echo -e "adb install $APK_PATH"
52+
else
53+
echo -e "${RED}Error: APK file not found at expected location!${NC}"
54+
exit 1
55+
fi
56+
else
57+
echo -e "${RED}Build failed!${NC}"
58+
exit 1
59+
fi

0 commit comments

Comments
 (0)