yasarefe commited on
Commit
83508c1
·
1 Parent(s): 8aeead2

Add Dockerfile, app.js, package.json for APK building

Browse files
Files changed (5) hide show
  1. Dockerfile +33 -0
  2. README.md +32 -5
  3. app.js +104 -0
  4. app.py +0 -0
  5. package.json +12 -0
Dockerfile ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:20
2
+
3
+ # Install Java
4
+ RUN apt-get update && apt-get install -y openjdk-17-jdk
5
+
6
+ # Install Android SDK
7
+ ENV ANDROID_HOME=/opt/android-sdk
8
+ ENV PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools
9
+ RUN mkdir -p ${ANDROID_HOME}/cmdline-tools && \
10
+ cd ${ANDROID_HOME}/cmdline-tools && \
11
+ curl -o cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip && \
12
+ unzip cmdline-tools.zip && \
13
+ mv cmdline-tools cmdline-tools-latest && \
14
+ rm -f cmdline-tools.zip
15
+
16
+ # Accept licenses
17
+ RUN yes | sdkmanager --licenses
18
+
19
+ # Install Capacitor CLI
20
+ RUN npm install -g @capacitor/cli @capacitor/core @capacitor/android
21
+
22
+ # Copy app
23
+ COPY . /app
24
+ WORKDIR /app
25
+
26
+ # Install dependencies
27
+ RUN npm install
28
+
29
+ # Expose port
30
+ EXPOSE 7860
31
+
32
+ # Start the web server
33
+ CMD ["node", "app.js"]
README.md CHANGED
@@ -1,10 +1,37 @@
1
  ---
2
- title: AIStudioToApp2 Apk Builder
3
- emoji: 🏆
4
- colorFrom: pink
5
- colorTo: yellow
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: AIStudioToApp2 APK Builder
3
+ emoji: 📱
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: docker
7
  pinned: false
8
+ license: mit
9
  ---
10
 
11
+ # AIStudioToApp2 APK Builder
12
+
13
+ Bu Hugging Face Space, web uygulamanızı Android APK'ya dönüştürmek için kullanılır.
14
+
15
+ ## Nasıl Kullanılır?
16
+
17
+ 1. Space'in web arayüzüne gidin.
18
+ 2. "APK Build Başlat" butonuna tıklayın.
19
+ 3. Build işlemi tamamlandıktan sonra APK'yı indirin.
20
+
21
+ ## Teknik Detaylar
22
+
23
+ - Node.js 20
24
+ - Java 17
25
+ - Android SDK
26
+ - Capacitor CLI
27
+ - Express.js web sunucusu
28
+
29
+ ## API Endpoint'leri
30
+
31
+ - `GET /` - Web arayüzü
32
+ - `POST /APK build işlemini başlatır`
33
+ - `GET /download` - Oluşturulan APK'yı indirir
34
+
35
+ ## Kaynak Kodu
36
+
37
+ GitHub: https://github.com/nyx47rd/AIStudioToApp2
app.js ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const { exec } = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const app = express();
7
+ const PORT = 7860;
8
+
9
+ // Web arayüzü
10
+ app.get('/', (req, res) => {
11
+ res.send(`
12
+ <html>
13
+ <head>
14
+ <title>APK Build Service</title>
15
+ <style>
16
+ body { font-family: Arial, sans-serif; margin: 40px; }
17
+ button { padding: 10px 20px; font-size: 16px; cursor: pointer; }
18
+ #status { margin-top: 20px; padding: 10px; border: 1px solid #ccc; }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <h1>APK Build Service</h1>
23
+ <p>Web uygulamanızı APK'ya dönüştürün.</p>
24
+ <button onclick="startBuild()">APK Build Başlat</button>
25
+ <div id="status"></div>
26
+ <script>
27
+ function startBuild() {
28
+ document.getElementById('status').innerHTML = 'Build başlatılıyor...';
29
+ fetch('/build', { method: 'POST' })
30
+ .then(response => response.json())
31
+ .then(data => {
32
+ document.getElementById('status').innerHTML = data.message;
33
+ if (data.success) {
34
+ document.getElementById('status').innerHTML += '<br><a href="/download">APK İndir</a>';
35
+ }
36
+ })
37
+ .catch(error => {
38
+ document.getElementById('status').innerHTML = 'Hata: ' + error;
39
+ });
40
+ }
41
+ </script>
42
+ </body>
43
+ </html>
44
+ `);
45
+ });
46
+
47
+ // Build endpoint
48
+ app.post('/build', (req, res) => {
49
+ console.log('Build başlatıldı');
50
+
51
+ // GitHub'dan web uygulamasını çek
52
+ const repoUrl = 'https://github.com/nyx47rd/AIStudioToApp2.git';
53
+ const buildDir = '/tmp/build';
54
+
55
+ // Temizle
56
+ if (fs.existsSync(buildDir)) {
57
+ fs.rmSync(buildDir, { recursive: true });
58
+ }
59
+
60
+ // Klonla
61
+ exec(`git clone ${repoUrl} ${buildDir}`, (error, stdout, stderr) => {
62
+ if (error) {
63
+ console.error('Klonlama hatası:', error);
64
+ return res.json({ success: false, message: 'Repo klonlanamadı: ' + error.message });
65
+ }
66
+
67
+ // Build işlemi
68
+ exec('npm install && npm run build && npx cap init "AIStudioToApp2" "com.example.aistudiotoapp2" --web-dir dist && npx cap add android && npx cap sync android && cd android && chmod +x gradlew && ./gradlew assembleDebug',
69
+ { cwd: buildDir },
70
+ (error, stdout, stderr) => {
71
+ if (error) {
72
+ console.error('Build hatası:', error);
73
+ return res.json({ success: false, message: 'Build başarısız: ' + error.message });
74
+ }
75
+
76
+ // APK'yı kopyala
77
+ const apkPath = path.join(buildDir, 'android/app/build/outputs/apk/debug/app-debug.apk');
78
+ const destPath = '/tmp/app-debug.apk';
79
+
80
+ if (fs.existsSync(apkPath)) {
81
+ fs.copyFileSync(apkPath, destPath);
82
+ console.log('APK oluşturuldu:', destPath);
83
+ res.json({ success: true, message: 'APK başarıyla oluşturuldu!' });
84
+ } else {
85
+ res.json({ success: false, message: 'APK dosyası bulunamadı.' });
86
+ }
87
+ }
88
+ );
89
+ });
90
+ });
91
+
92
+ // APK indirme endpoint
93
+ app.get('/download', (req, res) => {
94
+ const apkPath = '/tmp/app-debug.apk';
95
+ if (fs.existsSync(apkPath)) {
96
+ res.download(apkPath, 'app-debug.apk');
97
+ } else {
98
+ res.status(404).send('APK dosyası bulunamadı. Önce build yapın.');
99
+ }
100
+ });
101
+
102
+ app.listen(PORT, () => {
103
+ console.log(`Sunucu ${PORT} portunda çalışıyor`);
104
+ });
app.py ADDED
File without changes
package.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "apk-builder",
3
+ "version": "1.0.0",
4
+ "description": "APK Build Service for Hugging Face Space",
5
+ "main": "app.js",
6
+ "scripts": {
7
+ "start": "node app.js"
8
+ },
9
+ "dependencies": {
10
+ "express": "^4.18.2"
11
+ }
12
+ }