openEventsPlatformApp/plugins/cordova-plugin-compat/src/android/BuildHelper.java
plugins/cordova-plugin-compat/src/android/BuildHelper.javaRaw
1/*
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18*/
19
20package org.apache.cordova;
21
22/*
23 * This is a utility class that allows us to get the BuildConfig variable, which is required
24 * for the use of different providers. This is not guaranteed to work, and it's better for this
25 * to be set in the build step in config.xml
26 *
27 */
28
29import android.app.Activity;
30import android.content.Context;
31
32import java.lang.reflect.Field;
33
34
35public class BuildHelper {
36
37
38 private static String TAG="BuildHelper";
39
40 /*
41 * This needs to be implemented if you wish to use the Camera Plugin or other plugins
42 * that read the Build Configuration.
43 *
44 * Thanks to Phil@Medtronic and Graham Borland for finding the answer and posting it to
45 * StackOverflow. This is annoying as hell! However, this method does not work with
46 * ProGuard, and you should use the config.xml to define the application_id
47 *
48 */
49
50 public static Object getBuildConfigValue(Context ctx, String key)
51 {
52 try
53 {
54 Class<?> clazz = Class.forName(ctx.getPackageName() + ".BuildConfig");
55 Field field = clazz.getField(key);
56 return field.get(null);
57 } catch (ClassNotFoundException e) {
58 LOG.d(TAG, "Unable to get the BuildConfig, is this built with ANT?");
59 e.printStackTrace();
60 } catch (NoSuchFieldException e) {
61 LOG.d(TAG, key + " is not a valid field. Check your build.gradle");
62 } catch (IllegalAccessException e) {
63 LOG.d(TAG, "Illegal Access Exception: Let's print a stack trace.");
64 e.printStackTrace();
65 }
66
67 return null;
68 }
69
70}