()
| 116 | |
| 117 | |
| 118 | function enableLegacyJni() { |
| 119 | const prefix = execSync('npm prefix').toString().trim(); |
| 120 | const gradleFile = path.join(prefix, 'platforms/android/app/build.gradle'); |
| 121 | |
| 122 | if (!fs.existsSync(gradleFile)){ |
| 123 | console.warn('[Cordova Hook] ⚠️ build.gradle not found'); |
| 124 | return |
| 125 | }; |
| 126 | |
| 127 | let content = fs.readFileSync(gradleFile, 'utf-8'); |
| 128 | // Check for correct block to avoid duplicate insertion |
| 129 | if (content.includes('useLegacyPackaging = true')){ |
| 130 | console.log('[Cordova Hook] ✅ Legacy JNI packaging already enabled, skipping'); |
| 131 | return |
| 132 | }; |
| 133 | |
| 134 | // Inject under android block with correct Groovy syntax |
| 135 | content = content.replace(/android\s*{/, match => { |
| 136 | return ( |
| 137 | match + |
| 138 | ` |
| 139 | packagingOptions { |
| 140 | jniLibs { |
| 141 | useLegacyPackaging = true |
| 142 | } |
| 143 | }` |
| 144 | ); |
| 145 | }); |
| 146 | |
| 147 | fs.writeFileSync(gradleFile, content, 'utf-8'); |
| 148 | console.log('[Cordova Hook] ✅ Enabled legacy JNI packaging'); |
| 149 | } |
| 150 | |
| 151 | function enableStaticContext() { |
| 152 | try { |
no test coverage detected