Build types in Capacitor

#1

Hi there!

I’m looking for a way to incorporate build types into my capacitor. In cordova we could do this by adding a build-extras.gradle file. Now we do have a lot more control in our Android platform but when adding these build types I get an exception that there is no corresponding build type for the capacitor packages.

Unable to find a matching variant of project :capacitor-android:
  - Variant 'debugApiElements':
  - Required com.android.build.api.attributes.BuildTypeAttr 'beta' and found incompatible value 'debug'.
  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
  - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  - Variant 'debugRuntimeElements':
  - Required com.android.build.api.attributes.BuildTypeAttr 'beta' and found incompatible value 'debug'.
  - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
  - Required org.gradle.usage 'java-api' and found incompatible value 'java-runtime'.
  - Variant 'releaseApiElements':
  - Required com.android.build.api.attributes.BuildTypeAttr 'beta' and found incompatible value 'release'.
  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
  - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  - Variant 'releaseRuntimeElements':
  - Required com.android.build.api.attributes.BuildTypeAttr 'beta' and found incompatible value 'release'.
  - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
  - Required org.gradle.usage 'java-api' and found incompatible value 'java-runtime'.

Is there any possibility right now to do this? Basically what I want to add is multiple variants for beta/staging/production. All these apps will have something like this: applicationIdSuffix “.beta”. This will allow me to have multiple instances of my app on the same phone.

I haven’t tried this yet with iOS but I think it should work for iOS without any problems though.

0 Likes

#2

would be good if you say how and where are you adding the build types, by the message looks like you are adding them to Capacitor and not to your own project

0 Likes

#3

Hi Julio,

Well there exactly is the problem. I am adding the build types to my own app gradle files.

Then I try to build this variant by selecting it in the menu on the right. Here I see 3 row’s with build variants. Two from capacitor and one that is my own project. The two capacitor ones are generated ofcourse.

When I then select my custom build type here and try to build the project it will complain that I cannot use build_type debug or release for capacitor together with my new custom build type for app.

That’s the error shown in my first post.

I’ve done some thinking though and figured I could use the flavour system for this. I think that should work without needing another build type from capacitor but I have not tried this yet. If there is a better solution let me know :slight_smile:

0 Likes