Error upgrading unity project from android Google Play Billing Library v3 to v4

I managed to solve the issue. I had to experiment a little by exporting the project in an android studio project. I upgraded gradle, migrated to androidx and found the library responsible in the build.gradle from :unityLibrary and changed it from 15.0.1 to 16.0.1 and it still got the same error. When I put my mouse over the version it said that there is a newer version 20.1.3. So I replaced the previous version with this and it compiled successfully. When I build and signed from the android studio, it found problems on uploading regarding unity stuff (e.g. StreamingAssets files are compressed in APK when "Build App Bundle (Google Play)" option is used problem with capital letters), so it needed to be built from unity. Then I unchecked all the boxes from the custom files in Project Settings/Player/Build and it cleaned something, but when checked them again it failed with the same error. So I am not sure if this step helped at all.

[SOLUTION]
But then I found the settings from the previously mentioned build.gradle in the mainTemplate.gradle and copied some of the changes from the android studio gradle file. To be precise I changed the dependencies in comments to the ones without:

dependencies {
...
//implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
//implementation 'com.android.support:support-v4:28.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
//implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
...

I also put the Android Resolver Exclusions part and the rest of android options in the same android category like this:

android {
packagingOptions {
exclude ('/lib/armeabi/*' + '*')
exclude ('/lib/armeabi-v7a/*' + '*')
exclude ('/lib/mips/*' + '*')
exclude ('/lib/mips64/*' + '*')
exclude ('/lib/x86/*' + '*')
exclude ('/lib/x86_64/*' + '*')
}

aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}

compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
}

lintOptions {
abortOnError false
}
**PACKAGING_OPTIONS**
}

Then it built without errors.