googlesamples / unity-jar-resolver

Unity plugin which resolves Android & iOS dependencies and performs version management
Other
1.29k stars 347 forks source link

Limit upper bounds of com.android.support to compileSdkVersion #111

Open jkasten2 opened 6 years ago

jkasten2 commented 6 years ago

Issue

This resolver plugin should limit the upper bounds of all modules under the com.android.support group to match compileSdkVersion. Example if com.android.support revision 26 is used when Unity uses compileSdkVersion of 25 the following build error occurs.

Example Error 1

com.android.support = 26 compileSdkVersion = 25

CommandInvokationFailure: Gradle build failed. 
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java
   -classpath "/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-4.0.1.jar"
   org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m"
   "assembleRelease"
stderr[
   UnityProjectDir/Temp/gradleOut/build/intermediates/res/merged/release/values-v26/values-v26.xml:15:21-54:
      AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.    
   UnityProjectDir/Temp/gradleOut/build/intermediates/res/merged/release/values-v26/values-v26.xml:15:
      error: Error: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.

Example Error 2

com.android.support = 27.1.1 compileSdkVersion = 25

CommandInvokationFailure: Gradle build failed. 
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java -classpath "/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"

stderr[
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:font
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontStyle
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontWeight

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

Reproducing Issue

This is reproducible by using the following:

  1. Unity 2017.4.0f1 (Exact version probably not needed)
  2. File > Build Settings.. > Player Settings... > Target API Level
    • Android 7.1 'Nougat' (API Level 25) Or lower
  3. play-services-resolver-1.2.64.0.unitypackage
  4. OneSignalSDK.unitypackage - version 2.6.4 or any *Dependencies.xml file like OneSignal's

Work Arounds

Option 1

  1. Updated version of Unity
    • Tested with Unity 2017.4.0f1, might work on older versions
  2. Update to latest Android SDK
    • Platform-Tools 27+
    • Build Tools 27+ (Without 28.0.0-rc1)
  3. File > Build Settings.. > Player Settings... > Target API Level
    • Set as Automatic (highest installed)

      Option 2

  4. Steps 1 & 2 from Option 1
  5. File > Build Settings..
    • Set "Build System" to Gradle
    • Check "Export Project"
  6. Open app/build.gradle update compileSdkVersion to 27.

    Option 3

  7. Search for *Dependencies.xml files in your project
  8. Find lines that contain <androidPackage spec="com.android.support:
  9. Update the version to match what you have in File > Build Settings.. > Player Settings... > Target API Level
  10. WARNING: Forcing a lower version may here have side effects such as runtime issues on the library depending on what features it uses
stewartmiles commented 6 years ago

@jkasten2 does this jive with what the support library team is suggesting here https://developer.android.com/topic/libraries/support-library/index.html#api-versions ?

If we want to apply special logic around a dependency like this perhaps somewhere this could be applied is in https://github.com/googlesamples/unity-jar-resolver/blob/master/source/PlayServicesResolver/scripts/download_artifacts.gradle ?

jkasten2 commented 6 years ago

@stewartmiles The link talks about minimum API level, it doesn't bring up the compile SDK version though. Actually wasn't able to find a reference to the specific limitation of compileSdkVersion and com.android.support in any of the Google docs online docs. However this error is shown in Android Studio: image

It notes 'different' but I don't believe there will be an issue with the compileSdkVersion being greater than com.android.support. Only when compileSdkVersion is less than com.android.support as it's can refer to classes or resource names that isn't in the compile version referenced.

I might have so time to dig into this in the next week or 2. I see there is also a nice quick and easy to run test for this file ./gradlew test_downloadArtifacts that runs for me.

I am having some trouble with a full build however running ./gradlew build --info. I'll open a 2nd issue for this with more detail though, to keep this issue on a single topic.

asarazan commented 6 years ago

+1 on this, as it has been making my life hell the past few days.

Fyi @jkasten2 there is a 4th option, which is to create mainTemplate.gradle from Player Settings and override compileSdkVersion there instead of having to export!