0

I have built an Android App using Android Studio and I've been doing testing with a tablet running Android version 5.1.1 (API 22). Once the development was finished I tried using the APK to install the same app to an S7 running Android 8.0.0 (API 26). The app crashed while running on the S7, but runs flawlessly on the tablet. The target SDK version for the app I built is API 29 and the minimum SDK version is API 22.

I can change the compile SDK version from 29 to 28 and I don't get any build errors. However, changing it to 27 gives me the following errors:

Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
  C:\Users\xxxxx\.gradle\caches\transforms-2\files-2.1\9073307f5eb1fdd8dc5b08ac4a3a252e\res\values-v28\values-v28.xml:9:5-12:13: AAPT: error: resource android:attr/dialogCornerRadius not found.

  C:\Users\xxxxx\Desktop\appDev\app_green\myApp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: AAPT: error: resource android:attr/dialogCornerRadius not found.

  C:\Users\xxxxx\.gradle\caches\transforms-2\files-2.1\11ac981ad78c9fd8730f98006e1b2a23\res\values\values.xml:89:5-125:25: AAPT: error: resource android:attr/fontVariationSettings not found.

  C:\Users\xxxxx\.gradle\caches\transforms-2\files-2.1\11ac981ad78c9fd8730f98006e1b2a23\res\values\values.xml:89:5-125:25: AAPT: error: resource android:attr/ttcIndex not found.

  error: failed linking references.

I figured if I decreased the API level one by one and fixed any errors that popped up, I'd eventually end up with an app that would work on all the desired APIs. Is this a correct assumption?

How do I go about fixing errors like this one that fail to link Gradle resources? This one seems to be an error with a dialog box that I used to get user input.

All solutions to these errors that I find are "change API version," but what if I need this API version?

Edit: At the request of those attempting to help me solve this issue I am posting the crash log from the S7.

Process: com.myApp, PID: 15167
    android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/myApp/files/export_a_c.csv exposed beyond app through ClipData.Item.getUri()
        at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
        at android.net.Uri.checkFileUriExposed(Uri.java:2356)
        at android.content.ClipData.prepareToLeaveProcess(ClipData.java:944)
        at android.content.Intent.prepareToLeaveProcess(Intent.java:10480)
        at android.content.Intent.prepareToLeaveProcess(Intent.java:10486)
        at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
        at android.app.Activity.startActivityForResult(Activity.java:4564)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
        at android.app.Activity.startActivityForResult(Activity.java:4522)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:754)
        at com.example.myApp.SecondActivity$onCreate$3$3.onClick(SecondActivity.kt:218)
        at android.view.View.performClick(View.java:6897)
        at android.widget.TextView.performClick(TextView.java:12693)
        at android.view.View$PerformClick.run(View.java:26101)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

The error occurs when I try to create/write to a csv file. The intent is to create this file automatically and then prompt the user to share it via email.

Edit 2: So I've fixed the crash issue while running on the S7. How do I ensure that the app will run for each API? Must I downgrade my S7's software to the APIs I want to test?

Alex Marks
  • 66
  • 7
  • 1
    You shouldn't change the sdk version. Instead check why it's crashing and act accordingly. Add the crash log from the logcat here. – Shaiful Aug 20 '19 at 19:25
  • That would work for to make it work for API 26, but I don't have a device with every version of Android that I would like to support. So how do I make sure that it works with all of those APIs? – Alex Marks Aug 20 '19 at 19:28
  • If your app is running on older version, it'll run on newer version. On rare case something will not work. Add the crash log here so that everyone can check. – Shaiful Aug 20 '19 at 19:31
  • Check this. https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed – Shaiful Aug 20 '19 at 20:25
  • Adding "val openFilePolicy = StrictMode.VmPolicy.Builder()" and "StrictMode.setVmPolicy(openFilePolicy.build())" before attempting to share the file fixed the crash – Alex Marks Aug 20 '19 at 20:36
  • I'll suggest you to follow the accepted answer and create a `FileProvider`. – Shaiful Aug 20 '19 at 20:39

2 Answers2

0

Remove declaration for compile.sdk from your manifest and build.gradle. You should keep the min and build SDK version declarations only.

Samuel Owino
  • 747
  • 1
  • 12
  • 24
  • I am not changing anything in the Manifest. I only have min, max, and target SDK version in the Manifest. I'm changing the app module properties so that Android Studio uses API 27 to build the project. – Alex Marks Aug 20 '19 at 19:16
  • If you declare max SDK that will be the one used for compilation by default. What is your reason for changing this? – Samuel Owino Aug 20 '19 at 20:10
  • I explained why I am changing my compilation SDK in the question. I have an app that I developed that worked for API 22, but not 26. So I wanted to use the compiler to try and find the error, but it is not a syntax issue. I've posted my crash log above – Alex Marks Aug 20 '19 at 20:14
0

You will need to setup a File provider in the app. https://developer.android.com/training/secure-file-sharing/setup-sharing

Brandon McAnsh
  • 992
  • 8
  • 18