pwa-builder / PWABuilder-CLI

Node.js tool for App Generation
Other
1.63k stars 142 forks source link

Android Studio 3.0 default gradle build file fails due to old Gradle dependency #293

Open ghhv opened 6 years ago

ghhv commented 6 years ago

The Build Gradle dependency on line 34 of the build.gradle file generated by PWABuilder will not build with default Android Studio 3 due to the version being too old.

Error is similar to

Error:Gradle version 2.10 is required. Current version is 4.4. If using the gradle wrapper...

If Grade 2.x is installed, it will still fail as it needs something from a newer Gradle.

Existing Code:

dependencies { classpath 'com.android.tools.build:gradle:1.5.0' }

Fix Required to build: This needs to be updated to at least v3 as per dependencies { classpath 'com.android.tools.build:gradle:3.0.1' }

Can the build files generation be updated so the build works as is?

Thanks

boyofgreen commented 6 years ago

Thanks for the feedback. Does the gradle version update okay when android studio does it for you? its a lot to try to keep the gradle dependency at the right version, so we've always relayed on being able to easily upgrade.

ghhv commented 6 years ago

Unfortunately no.. you end up in a dependency loop where the system says it needs 2.2 when you have 4.x. When you downgrade gradle to 2.2, it says it's using a feature that needs a newer gradle and round you go.. the only fix is to change the base reference as above so it can use the newer gradle as required.

LucasBassetti commented 6 years ago

Same problem here. Any update about this issue?

cmdalbem commented 6 years ago

@LucasBassetti I managed to fix the problem and build the project. 1 - manually edit the Gradle dependency version as described in the original post text 2 - if it complains about not being able to resolve CordovaLib, apply the fix as described here: https://stackoverflow.com/questions/47263668/could-not-resolve-project-cordovalib

projecteon commented 5 years ago

Same issues and above answer by @cmdalbem did not help :/

raphaelmerx commented 5 years ago

An alternative is to build the app with gradle alone, without Android Studio. Following the documentation at https://developer.android.com/studio/build/building-cmdline:

cd Polyfills/cordova/platforms/android # from the pwabuilder project

# generate a keystore
keytool -genkey -v -keystore my-store.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-store

# build the unsigned apk
./gradlew assemble

# align the unsigned apk
cd build/outputs/apk
zipalign -v -p 4 android-release-unsigned.apk android-release-aligned.apk

# sign the aligned apk
apksigner sign --ks ../../../my-store.jks --out android-release.apk android-release-aligned.apk

The above generates android-release.apk, which can be uploaded to the Play Store.