In Marshmallow (and above), after you installed the application, simply run:
adb shell appops set com.example.my.package android:mock_location allow
hope this helps!
Some internal elements: the android: mock_location line is resolved by the AppOpsManager into the actual int and executed.
source share