Gyroscope is quite popular, one can even find it in iphone etc. But, is such Gyroscope the only way? are there any other ways to build machine that to measure or maintain the orientation?
No, they are not.
An example is the Solar and Heliospheric Observatory (SOHO) spacecraft:
Only one gyro remained operational after this recovery, and on December 21 that gyro failed. Attitude control was accomplished with manual thruster firings that consumed 7 kg of fuel weekly, while ESA developed a new gyroless operations mode that was successfully implemented on February 1, 1999.
Some time ago I asked this question on Space Exploration.SE on precisely this issue; the answer by Mark Adler gives a good explanation; essentially, in space it is possible to determine orientation using only star trackers.
This answer assumes the question is about determining rather than maintaining orientation.
Gyroscopes (at least the kind used in cell phones and inertial measurement systems) don't indicate where something is pointing. They instead indicate how fast something is rotating with respect to an inertial frame of reference. If an initial estimate of orientation exists, the angular rate information output from a gyroscope can integrated to yield an estimate of the orientation at some later point in time.
This integration has two key problems: The gyroscope output has both systemic and random errors. The systemic errors (bias) can be addressed to some extent by estimation techniques. The random errors: You're out of luck. Those random errors are close to white noise, and integrating white noise produces a random walk. Eventually, the orientation produced by integrating gyroscope output will be complete garbage. This is the dead reckoning problem. To make matters worse, the gyroscope bias itself changes, both systematically (e.g., temperature variations) and randomly. The gyro bias drift adds to the dead reckoning error.
The only way to combat dead reckoning errors is to obtain measurements of the integrated quantity, in this case, orientation. Smart phones and tablets oftentimes use a combination of magnetometers, accelerometers, and GPS to provide some kind of measurement of orientation.
Magnetometers aren't very precise, can be easily fooled by the nearby presence of magnetic substances or electric fields, and measure orientation with respect to the local magnetic field rather than true north. The final problem is easily fixed: The Earth's magnetic field changes slowly with time. The deviation between true north and magnetic force can be determined quite accurately from location (hence the need for GPS). This requires a mapping from position to magnetic field orientation, but that's not a problem since modern smart phones and tablets have lots of memory.
If the object is stationary with respect to the rotating earth, accelerometers can give a clue with regard to which way is down. That directional clue can be rather suspect if the object is accelerating. Sophisticated signal processing can help deduce which way is truly down. The equipment needs a mapping from position to the geoid to make sense of this determination of which way is down.
The above pertains to objects moving along the surface of the Earth. What about objects flying through the air or orbiting the Earth? Airplanes oftentimes rely on the Earth's horizon to provide additional measures of absolute orientation. This provides information on the pitch and roll angles, but not yaw. Something else (e.g., a compass bearing or magnetometer reading) is needed to help resolve roll.
Using an accelerometer to determine which way is down is absolutely useless for an orbiting spacecraft. Spacecraft have more or less unobstructed view of the stars. Modern spacecraft are typically equipped with star sensors to determine orientation. In addition to star sensors, spacecraft orbiting the Earth also use horizon sensors, sun sensors, and magnetometers to augment or replace those star sensors.
A number of gyroscopes can determine arbitrary rotations.
Cell phones instead use accelerometers to determine the direction of "down" (by assuming they are nearly at rest on earth), and they use magnetic sensors to determine what direction is pointing north. Together you get an orientation solution with no gyrosocpes.
Also, while gyroscopes can give you information about your turn rate with high precision, they are subject to precession errors over time. If you want them to tell you which way you are pointing, you have to correct their errors periodically. A combined accelerometer/magnetometer may not be as accurate, but it will be long-term stable after calibration.