Market discrimination apk and debug apk


There are 2 APIs, one for QA(testing and debugging) and the other for Production
I need to run QAapi for debugging (which we created using eclipse) and Productionapi when we create a market apk without changing the code. Is there any way to check if the code is using apk or apk apk currently. Or anything I can set in the manifest Thank you

+3
source share
4 answers

Here Ant can help you. I always use Eclipse to create a debug version, and then use Ant for the release version, mainly because each of them needs a different Google Maps API API. I have two versions of main.xml, namely debugmain.xml and releasemain.xml. I changed the release target in the build.xml file and added two additional goals:

<target name="check-release_main">
    <available file="${layout.dir}/releasemain.xml" property="releasemain.present" />
</target>


<target name="-copy-rel-main" depends="check-release_main" if="releasemain.present">
    <echo message="Hit copy rel main" />
    <copy file="${layout.dir}/releasemain.xml" tofile="${layout.dir}/main.xml" overwrite="true"/>
</target>

I changed the release target dependencies depending on copy-rel-main:

<target name="release" depends="clean, -copy-rel-main....... 

and at the very end of the release target, the debug version of main.xml is copied to overwrite main.xml back into the debug version

    ......
    <echo message="Copying the debugmain.xml back to main.xml" />
    <echo message="ALWAYS LEFT IN DEBUG FROR ECLIPSE" />
    <copy file="${layout.dir}/debugmain.xml" tofile="${layout.dir}/main.xml" overwrite="true" />

</target>

You can adapt your versions to have a specific identification text or color in one of your elements to indicate which version works on your device.

+1
source

, . , . . Google

+1

You can store a boolean in your XML files along with the lines:

<resources>
  <bool name="debug">true</bool>
</resources>

and then access it in your code using this.getResources().getBoolean(R.debug)(where thisis the action or other context). Store it truemost of the time, and then set the value for it false.

+1
source

You can also programmatically verify the signature of your application. I use this technique to record version information

final byte[] officalkey = {-58, -42, -44, -106, 90, -88, -87, -88, -52, -124, 84, 117, 66, 79, -112, -111, -46, 86, -37, 109};
final byte[] officaldebugkey = {-99, -69, 45, 71, 114, -116, 82, 66, -99, -122, 50, -70, -56, -111, 98, -35, -65, 105, 82, 43};

Signature raw = c.getPackageManager().getPackageInfo(c.getPackageName(), PackageManager.GET_SIGNATURES).signatures[0];
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(raw.toByteArray()));
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] der = cert.getEncoded();
md.update(der);
byte[] digest = md.digest();


if (Arrays.equals(digest, officalkey))
    apksign = c.getString(R.string.official_build);
else if (Arrays.equals(digest, officaldebugkey))
    apksign = c.getString(R.string.debug_build);
else
    apksign = c.getString(R.string.built_by,cert.getSubjectX500Principal().getName());
0
source

Source: https://habr.com/ru/post/1784886/


All Articles