Search Unity

Access to disk works only in development build

Discussion in 'Scripting' started by justtime, Mar 6, 2019.

  1. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    339
    Hi there!
    Unity 2017.4.21f
    I am making android app, and need to save/load data. Disk access is working only when i build in development mode.
    My AndroidManifest's part

    Code (CSharp):
    1. <!--<uses-permission android:name="android.permission.RECORD_AUDIO" tools:node="remove"/>-->
    2.     <uses-feature android:name="android.hardware.location" android:required="false"/>
    3.     <!--<uses-feature android:name="android.permission.RECORD_AUDIO" android:required="false"/>-->
    4.     <uses-feature android:name="android.hardware.location.network" android:required="false"/>
    5.     <uses-feature android:name="android.hardware.telephony" android:required="false"/>
    6.     <uses-feature android:name="android.hardware.camera" android:required="false"/>
    7.     <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
    8.  
    9.     <uses-permission android:name="android.permission.INTERNET"/>
    10.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    11.     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    After run i accept all permissions but still can't access to disk. In 2017.2 it worked fine.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,757
    Perhaps show us your write code... also how are you checking if it works or not?
     
  3. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    339
    I use simple operations,nothing special, for example from this package https://assetstore.unity.com/packages/tools/simple-disk-utils-59382.
    Code (CSharp):
    1. #if UNITY_ANDROID && !UNITY_EDITOR
    2.  
    3.         return DiskUtils.CheckAvailableSpace(true);
    4.  
    5.         #endif
    6.      
    7.         return DiskUtils.CheckAvailableSpace();
    Unity 2017.2(release) and 2017.4(development) builds show actual free space, but 2017.4(release) shows nothing.
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,757
    Did you run logcat to see if you are getting any errors? Or an in app console asset?
     
  5. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    339
    Code (CSharp):
    1. 03-06 18:47:08.645  2468  2545 I Unity   : UnityEngine.AndroidJavaException: java.lang.ClassNotFoundException: com.dikra.diskutils.DiskUtils
    2. 03-06 18:47:08.645  2468  2545 I Unity   :   at UnityEngine.AndroidJNISafe.CheckException () [0x00091] in <9a162292ef6c4c0c85f59cb8a6026dad>:0
    3. 03-06 18:47:08.645  2468  2545 I Unity   :   at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (System.IntPtr clazz, System.IntPtr methodID, UnityEngine.jvalue[] args) [0x00011] in <9a162292ef6c4c0c85f59cb8a6026dad>:0
    4. 03-06 18:47:08.645  2468  2545 I Unity   :   at UnityEngine.AndroidJavaObject._CallStatic[ReturnType] (System.String methodName, System.Object[] args) [0x002d6] in <9a162292ef6c4c0c85f59cb8a6026dad>:0
    5. 03-06 18:47:08.645  2468  2545 I Unity   :   at UnityEngine.AndroidJavaObject.CallStatic[ReturnType] (System.String methodName, System.Object[] args) [0x00001] in <9a162292ef6c4c0c85f59cb8a6026dad>:0
    6. 03-06 18:47:08.645  2468  2545 I Unity   :   at UnityEngine.AndroidJavaObject.FindClass (System.String name) [0x0001d] in <9a162292ef6c4c0c85f59cb8a6026dad>:0
    7. 03-06 18:47:08.645  2468  2545 I Unity   :   at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00012] in <9a162292ef6c4c0c85f59cb8a6026dad>:0
    8. 03-06 18:47:08.645  2468  2545 I Unity   :   at UnityEngine.AndroidJavaClass..ctor (System.String className) [0x00007] in <9a
    9. 03-06 18:47:08.645  2468  2545 I Unity   : java.lang.ClassNotFoundException: com.dikra.diskutils.DiskUtils
    10. 03-06 18:47:08.645  2468  2545 I Unity   :
    11. 03-06 18:47:08.645  2468  2545 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    12. 03-06 18:47:08.645  2468  2545 I Unity   :
    13. 03-06 18:47:08.676  2468  2545 E Unity   : AndroidJavaException: java.lang.ClassNotFoundException: com.dikra.diskutils.DiskUtils
    14. 03-06 18:47:08.676  2468  2545 E Unity   : java.lang.ClassNotFoundException: com.dikra.diskutils.DiskUtils
    15. 03-06 18:47:08.676  2468  2545 E Unity   :      at java.lang.Class.classForName(Native Method)
    16. 03-06 18:47:08.676  2468  2545 E Unity   :      at java.lang.Class.forName(Class.java:324)
    17. 03-06 18:47:08.676  2468  2545 E Unity   :      at java.lang.Class.forName(Class.java:285)
    18. 03-06 18:47:08.676  2468  2545 E Unity   :      at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    19. 03-06 18:47:08.676  2468  2545 E Unity   :      at com.unity3d.player.UnityPlayer.c(Unknown Source)
    20. 03-06 18:47:08.676  2468  2545 E Unity   :      at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source)
    21. 03-06 18:47:08.676  2468  2545 E Unity   :      at android.os.MessageQueue.next(MessageQueue.java:392)
    22. 03-06 18:47:08.676  2468  2545 E Unity   :      at android.os.Looper.loop(Looper.java:135)
    23. 03-06 18:47:08.676  2468  2545 E Unity   :      at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
    24. 03-06 18:47:08.676  2468  2545 E Unity   : Caused by: java.lang.ClassNotFoundException: Didn't find class "com.dikra.diskutils.DiskUtils" on path: DexPathList[[zip file "/data/app/com.teq.guitarjam-1/base.apk"],nativeLibraryDirectories=[/data/app/com.teq.guitarjam-1/lib/arm, /data/app/com.teq.guitarjam-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
    25. 03-06 18:47:08.676  2468  2545 E Unity   :      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    26. 03-06 18:47:08.676  2468  2545 E Unity   :      at jav
    In dev build no error.
    May be something with my gradle...
    Code (CSharp):
    1. // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
    2. buildscript {
    3.     repositories {
    4.         google()
    5.         jcenter()
    6.     }
    7.  
    8.     dependencies {
    9.         classpath 'com.android.tools.build:gradle:3.2.0'
    10.     }
    11. }
    12.  
    13. allprojects {
    14.    repositories {
    15.       google()
    16.       jcenter()
    17.       flatDir {
    18.         dirs 'libs'
    19.       }
    20.    }
    21. }
    22.  
    23. apply plugin: 'com.android.application'
    24.  
    25. dependencies {
    26.     compile fileTree(dir: 'libs', include: ['*.jar'])
    27.     compile 'com.android.support:multidex:1.0.3'
    28. **DEPS**}
    29.  
    30. android {
    31.     compileSdkVersion **APIVERSION**
    32.     buildToolsVersion '**BUILDTOOLS**'
    33.  
    34.     defaultConfig {
    35.         minSdkVersion **MINSDKVERSION**
    36.         targetSdkVersion **TARGETSDKVERSION**
    37.         multiDexEnabled true
    38.         applicationId '**APPLICATIONID**'
    39.         ndk {
    40.             abiFilters **ABIFILTERS**
    41.         }
    42.        
    43.         versionCode 1029
    44.     }
    45.  
    46.     lintOptions {
    47.         abortOnError false
    48.     }
    49.  
    50.     aaptOptions {
    51.         noCompress '.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**
    52.     }
    53.  
    54. **SIGN**
    55.     buildTypes {
    56.           debug {
    57.              minifyEnabled **MINIFY_DEBUG**
    58.              useProguard **PROGUARD_DEBUG**
    59.              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    60.               jniDebuggable true
    61.           }
    62.           release {
    63.              minifyEnabled **MINIFY_RELEASE**
    64.              useProguard **PROGUARD_RELEASE**
    65.               proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    66.               **SIGNCONFIG**
    67.           }
    68.     }
    69.    
    70.    
    71. **PACKAGING_OPTIONS**
    72.     bundle {
    73.         language {
    74.             enableSplit = false
    75.         }
    76.         density {
    77.             enableSplit = false
    78.         }
    79.         abi {
    80.             enableSplit = true
    81.         }
    82.     }
    83. }
    84.  
    85.  
    86. **SOURCE_BUILD_SETUP**
     
    Last edited: Mar 6, 2019
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,757
    Well, based on that it's not including the native plugin code in the build. If this is a gradle build, you may have to modify the progaurd file to make sure it includes the plugin classes. I know I had to do this before when I'd build to Android studios and did a gradle build from there, but I haven't tried this from Unity yet to be honest.

    If still available, you could try an internal build instead, but that is going away and gradle will be the only option.

    In Unity there should be a proguard-unity file that you want to add in for it to keep that class instead of stripping it.
     
  7. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    339
    Thanks, i'll try to do something. Do you mean something like this ?
    Code (CSharp):
    1. -keep class com.appodealx.** { *; }
    Another side android plugin for permissions behaves in similar way...i am just curious whythis happens in release build only.
     
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,757
    Development build I don't think strips anything and adds additional stuff to help you debug and fix stuff. Release tries to strip out stuff it doesn't think you need. The proguard file just is a way to say hey, don't remove this I am actually using it somewhere.

    This is why a development build is larger than a release build.
     
    justtime likes this.
  9. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    339
    Thanks a lot, it really works =)
     
  10. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,757
    Nice, glad it is working. This will also be helpful hopefully to others as gradle builds will soon be the only build option and others will start running into this problem as well.